-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Optimize the size of the coroutines library in Android projects #1282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cf305a8
to
92d1c17
Compare
Can you please comment a little on |
It is just code-size optimization. |
Hum OK thanks I'll continue to search why there's no many threads created and how to mitigate then :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document all these hacks in the single document for the sake of future development.
Also, we should know what we are optimizing: debug builder, release build, minified build?
3644237
to
3436ac8
Compare
b014114
to
abd1ef6
Compare
I've cleaned up this PR, removed questionable optimizations, no more messing up with scheduler (scheduler is quite smaller now anyway). All the rules are bundled in the jar for R6 1.6.0+. Verified to work in a test project using AGP 4.0.0-alpha06. This PR saves additional 16Kb is DEX size in addition to savings you get by simply using a newer R8 version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
ui/kotlinx-coroutines-android/src/AndroidExceptionPreHandler.kt
Outdated
Show resolved
Hide resolved
ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro
Show resolved
Hide resolved
9f993e7
to
7458dd7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! Could you please fix the remaining issue, rebase this branch on develop
and do one more last measurement before the merge?
7458dd7
to
ce37412
Compare
Works like a charm. Now also reports the size of the optimized android DEX file for basic coroutine usage: https://teamcity.jetbrains.com/project/KotlinTools_KotlinxCoroutines?mode=builds&projectTab=stats |
Includes additional R8 rules to disable debugging & stack-trace recovery in optimized Android builds. Additional savings with AGP 4.0.0-alpha06 (r8-2.0.4-dev) are ~16kb in uncompressed DEX size. Tests are modified to verify that the classes that are supposed to be removed are indeed removed.
ce37412
to
fead427
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀🚀🚀
updated (see below)