New issue
Advanced search Search tips

Issue 800487 link

Starred by 2 users

Issue metadata

Status: Untriaged
Owner: ----
Cc:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

100ms gap before AsyncInitializationActivity.onCreate() on N5X

Project Member Reported by dskiba@chromium.org, Jan 9 2018

Issue description

In traces produced by experimental.startup.android.coldish bot I've noticed that there is ~100ms gap before onCreate() is called. I've been working with gobo devices running Android O and never saw the gap so huge, usually it's ~30ms.

See the screenshots.

"n5x" is a trace from experimental.startup.android.coldish:
  the gap is 117ms
  AsyncInitializationActivity.onCreate() is 330ms
  setContentView() is 215ms

"62_gobo" is a atrace of Chrome M62 running on gobo 1GiB device:
  the gap is 32ms
  AsyncInitializationActivity.onCreate() is 379ms
  setContentView() is 245ms


 
n5x.png
35.1 KB View Download
62_gobo.png
25.4 KB View Download
62_gobo.html.gz
2.9 MB Download
Labels: Performance-Startup
Labels: -OS-iOS
Hmm, in the metadata for the telemetry trace I see that os-arch is "armv8l" - are testing 64-bit Chrome builds?

Comment 4 by pasko@chromium.org, Jan 12 2018

I checked recent logs on the bot, the builds are 32bit.

recent log I took: https://logs.chromium.org/v/?s=chrome%2Fbb%2Fchromium.perf.fyi%2FAndroid_Nexus_5X_Perf_FYI%2F1511%2F%2B%2Frecipes%2Fsteps%2Fextract_build%2F0%2Fstdout

so perhaps os-arch corresponds to the OS on the device?

Comment 5 by pasko@chromium.org, Jan 12 2018

on recent benchmark runs I see the gap to be more like 60-65ms

Comment 6 by dskiba@chromium.org, Jan 12 2018

Yup, I thought os-arch comes from JNI (and 32-bit apps see 32-bit ABI), but it turns out it comes from uname.
OK, so I investigated this a bit. First, the same thing happens on sprout (1GiB Android One device) running M.

Next, I hacked ActivityThread and replaced Instrumentation instance with one that uses TraceEvents: https://chromium-review.googlesource.com/c/chromium/src/+/832819/6/base/android/java/src/org/chromium/base/TracingInstrumentation.java

Turned out that Instrumentation.newActivity(ClassLoader,...) is what is consuming all time. I investigated a bit deeper and found that (n5x-newActivity.png):

1. ClassLoader.loadClass("org.chromium.chrome.browser.ChromeTabbedActivity") took 6ms.

2. Instantiating that class took 76ms.
  2.1. 74ms passed until AsyncInitializationActivity <cinit> was run (i.e. class was loaded).

3. After loading and instantiating a class, TracingInstrumentation.newActivity() called the default implementation, which did the same (loading / instantiating a class) in just 0.1ms.

Based on this I suspect that the time is taken by loading base classes of AsyncInitializationActivity. But not android.app.Activity itself - traces from experimental.startup.android.coldish go through ChromeLauncherActivity, which loads android.app.Activity before routing to CTA, and still shows 100ms gap.


n5x-newActivity.png
28.8 KB View Download
sprout-newActivity.png
37.2 KB View Download
n5x-newActivity.html.gz
1.1 MB Download

Comment 8 by pasko@chromium.org, Feb 7 2018

Cc: lizeb@chromium.org mattcary@chromium.org
nice! so if instantiating AsyncInitializationActivity takes so long, then 'DEX ordering' has large potential! (+mattcary, +lizeb)

dskiba: did you experiment with newly installed APK each time? Does it manifest the same behavior on consequent warm runs?
This happens on consecutive warm runs on both Nexus 5X (running N) and sprout (running M). But the gap is ~30ms on gobo running O, so it looks they optimized that (I need to test on some other phone running O though).
Cc: yfried...@chromium.org
Cc: agrieve@chromium.org
+agrieve in case anything jumps out related to dexloading
Status: Available (was: Untriaged)
Sounds like a dex locality thing. From this year's IO, it was pointed out that O optimizes start-up classes better:
https://youtu.be/Yi9-BqUxsno?list=PLOU2XLYxmsIInFRc3M44HUTQc3b_YJ4-Y&t=915

Could also be that O has a faster dex verify step. If this is true, then having it reference fewer other classes would speed it up.
Status: Untriaged (was: Available)
Available, but no owner or component? Please find a component, as no one will ever find this without one.

Sign in to add a comment