-
Notifications
You must be signed in to change notification settings - Fork 710
MainDispatcherLoader.<clinit>
unexpectedly takes 209ms to run on COLD MAIN start up
#5102
Comments
We see a similar issue in fenix: https://share.firefox.dev/3CPxBEH It also does a long, |
I looked into the It seems like the coroutines library is calling a slow method, We recently upgraded AGP, kotlin, coroutines, etc. so maybe that's why we saw this regression. |
It looks like we have the latest version of the Android Gradle Plugin, v7.0.0 so it seems we can't modify the versions to fix this issue. Looking at blame of the code I linked above, this coroutine code was written 2 years ago: that implies that maybe the later releases of AGP may have broken this optimization. They also allude to a need for us to manually disable the fast service loader in the commit that added the code so maybe there's a configuration issue. |
I downgraded AGP to 4.2.0 (and removed compose during a previous debugging attempt) and no longer see the issue: https://share.firefox.dev/3fVvG7H Let's:
|
PromptMiddleware.<init>
unexpectedly takes 209ms to run on COLD MAIN start upMainDispatcherLoader.<cinit>
unexpectedly takes 209ms to run on COLD MAIN start up
I confirmed this is a regression from AGP v7.0.0 by creating a minimally reproducible test case: https://github.com/mcomella/AGP7Slowdown I filed an upstream bug with the R8 team: https://issuetracker.google.com/issues/196302685 Since this affects fenix, I filed: mozilla-mobile/fenix#20824 As for what we can do about this, we should probably just downgrade to AGP v4.2.0 until this is addressed upstream. An alternative would be to use the fast ServiceLoader via |
When I downgrade to AGP v4.2.0, I get the following error:
Which is weird because we explicitly declare kotlin 1.5.10 – I guess our dependencies are pulling in an older version that somehow gets upgraded with AGP v7.0.0. We could either:
|
This regressed in 6caa946. As far as I can tell, this is not in the v91.1.1 release:
I do not see tags for beta releases so I'm not sure how those work for Focus. Presumably, we just need to fix this before the v92 release, which probably follows the same train as Fenix: that's in 24 days. |
MainDispatcherLoader.<cinit>
unexpectedly takes 209ms to run on COLD MAIN start upMainDispatcherLoader.<clinit>
unexpectedly takes 209ms to run on COLD MAIN start up
In my local benchmark, this improved start up by 97ms. I filed #5121 as a follow-up to remove the hack. |
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
Actually, if our proguard code fails, it'll fall back on the r8 optimization anyway: it doesn't seem worth the churn to keep track of the upstream fix and remove it, especially for two products. I wanted to verify that the perf of the fast service loader and the r8 optimization are comparable so I took benchmarks: the fast service loader made start up 45ms faster but I realized this isn't a fair comparison as we downgraded our version of R8 and may be missing other optimizations. I could take a benchmark of just main scope but I think I spent enough time on this. We don't see a major perf hit in the profile so I think we can deal with it. If we later see a perf hit in the profile, then we can worry about it again. |
…'ll remove this later.
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
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)
…s later. (cherry picked from commit f600bbc)
Here's my PR in which I also requested a backport to v92: #5122 |
Backport PR: #5158 The original PR is closed. |
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)
…s later. (cherry picked from commit f600bbc)
Both main branch and releases branch is updated: closing as fixed. |
I took a profile of COLD MAIN start up on my Moto G5: https://share.firefox.dev/3iFn6LU
The main thing that appears unnecessarily slow is the
PromptMiddleware.<init>
call: let's investigate!The text was updated successfully, but these errors were encountered: