Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
For #5102: use fast service loader via ProGuard.
Browse files Browse the repository at this point in the history
For the root cause, see the comments added in the commit.

This improves COLD MAIN time to first frame by 97ms across 10
iterations (medians):
- before: 616.5ms
- after: 519.5ms

(cherry picked from commit 162e5bf)
  • Loading branch information
mcomella authored and mergify[bot] committed Aug 18, 2021
1 parent a3e204d commit 7c3eabd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,21 @@
public static int i(...);
public static int d(...);
}

####################################################################################################
# kotlinx.coroutines: use the fast service loader to init MainDispatcherLoader by including a rule
# to rewrite this property to return true:
# https://github.com/Kotlin/kotlinx.coroutines/blob/8c98180f177bbe4b26f1ed9685a9280fea648b9c/kotlinx-coroutines-core/jvm/src/internal/MainDispatchers.kt#L19
#
# R8 is expected to optimize the default implementation to avoid a performance issue but a bug in R8
# as bundled with AGP v7.0.0 causes this optimization to fail so we use the fast service loader instead. See:
# https://github.com/mozilla-mobile/focus-android/issues/5102#issuecomment-897854121
#
# The fast service loader appears to be as performant as the R8 optimization, however, this proguard
# implementation is more fragile because it relies upon the coroutines source not changing. We
# should back this out when the R8 bug is solved. We are tracking this in:
# https://github.com/mozilla-mobile/focus-android/issues/5121
####################################################################################################
-assumenosideeffects class kotlinx.coroutines.internal.MainDispatcherLoader {
boolean FAST_SERVICE_LOADER_ENABLED return true;
}

0 comments on commit 7c3eabd

Please sign in to comment.