Skip to content

Commit 9f993e7

Browse files
committed
~ review updates and more docs on debugging effect
1 parent abd1ef6 commit 9f993e7

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ threads are handled by Android runtime.
165165
#### R8 and ProGuard
166166

167167
R8 and ProGuard rules are bundled into the [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android) module.
168-
For best results it is recommended to use a recent version of R8.
169-
R8 is a replacement for ProGuard in Android ecosystem, it is enabled by default since Android gradle plugin 3.4.0
170-
(3.3.0-beta also had it enabled). The upcoming AGP 4.0.0 has never R8 and additional rules enable
171-
more optimizations, producing smaller binary size.
168+
For more details see ["Optimization" section for Android](ui/kotlinx-coroutines-android/README.md#optimization).
172169

173170
### JS
174171

docs/debugging.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
* [Stacktrace recovery machinery](#stacktrace-recovery-machinery)
99
* [Debug agent](#debug-agent)
1010
* [Debug agent and Android](#debug-agent-and-android)
11+
* [Android optimization](#android-optimization)
1112

1213
<!--- END_TOC -->
1314

14-
1515
## Debugging coroutines
16+
1617
Debugging asynchronous programs is challenging, because multiple concurrent coroutines are typically working at the same time.
1718
To help with that, `kotlinx.coroutines` comes with additional features for debugging: debug mode, stacktrace recovery
1819
and debug agent.
@@ -87,6 +88,14 @@ java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/Mana
8788
at kotlinx.coroutines.debug.DebugProbes.install(DebugProbes.kt:49)
8889
-->
8990

91+
## Android optimization
92+
93+
In optimized (release) builds with R8 version 1.6.0 or later both
94+
[Debugging mode](../../docs/debugging.md#debug-mode) and
95+
[Stacktrace recovery](../../docs/debugging.md#stacktrace-recovery)
96+
are permanently turned off.
97+
For more details see ["Optimization" section for Android](../ui/kotlinx-coroutines-android/README.md#optimization).
98+
9099
<!--- MODULE kotlinx-coroutines-core -->
91100
<!--- INDEX kotlinx.coroutines -->
92101
[DEBUG_PROPERTY_NAME]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-n-a-m-e.html

kotlinx-coroutines-core/jvm/src/internal/MainDispatchers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public fun MainCoroutineDispatcher.isMissing(): Boolean = this is MissingMainCor
6565

6666
// R8 optimization hook, not const on purpose to enable R8 optimizations via "assumenosideeffects"
6767
@Suppress("MayBeConstant")
68-
val SUPPORT_MISSING = true
68+
private val SUPPORT_MISSING = true
6969

7070
@Suppress("ConstantConditionIf")
7171
private fun createMissingDispatcher(cause: Throwable? = null, errorHint: String? = null) =

ui/kotlinx-coroutines-android/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ Provides `Dispatchers.Main` context for Android applications.
55
Read [Guide to UI programming with coroutines](https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md)
66
for tutorial on this module.
77

8+
# Optimization
9+
10+
R8 and ProGuard rules are bundled into this module.
11+
R8 is a replacement for ProGuard in Android ecosystem, it is enabled by default since Android gradle plugin 3.4.0
12+
(3.3.0-beta also had it enabled).
13+
For best results it is recommended to use a recent version of R8, which produces a smaller binary.
14+
15+
When optimizations are enabled with R8 version 1.6.0 or later
16+
the following debugging features are permanently turned off to reduce the size of the resulting binary:
17+
18+
* [Debugging mode](../../docs/debugging.md#debug-mode)
19+
* [Stacktrace recovery](../../docs/debugging.md#stacktrace-recovery)
20+
* The internal assertions in the library are also permanently removed.
21+
22+
You can examine the corresponding rules in this
23+
[`coroutines.pro`](resources/META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro) file.
24+
825
# Package kotlinx.coroutines.android
926

1027
Provides `Dispatchers.Main` context for Android applications.

ui/kotlinx-coroutines-android/src/AndroidExceptionPreHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class AndroidExceptionPreHandler :
2121
private fun preHandler(): Method? {
2222
val current = _preHandler
2323
if (current !== this) return current as Method?
24-
val declared =try {
24+
val declared = try {
2525
Thread::class.java.getDeclaredMethod("getUncaughtExceptionPreHandler").takeIf {
2626
Modifier.isPublic(it.modifiers) && Modifier.isStatic(it.modifiers)
2727
}

ui/kotlinx-coroutines-android/testdata/r8-test-rules.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
-checkdiscard class kotlinx.coroutines.DebugKt
88
-checkdiscard class kotlinx.coroutines.internal.StackTraceRecoveryKt
99

10-
# Real android projects do not keep this class, but somehow it is kept in this test (R& bug)
10+
# Real android projects do not keep this class, but somehow it is kept in this test (R8 bug)
1111
# -checkdiscard class kotlinx.coroutines.internal.MissingMainCoroutineDispatcher
1212

13-
# Should not keep this class, but it is still there (R& bug)
13+
# Should not keep this class, but it is still there (R8 bug)
1414
#-checkdiscard class kotlinx.coroutines.CoroutineId

0 commit comments

Comments
 (0)