New issue
Advanced search Search tips

Issue 746936 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Feb 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 2
Type: Bug



Sign in to add a comment

CustomTabs warmup() bad for performance when called very close to Intent.

Project Member Reported by lizeb@chromium.org, Jul 20 2017

Issue description

When a Custom Tab is launched shortly after warmup() is called, it is queued after Chrome synchronous initialization taking place in a single task on the UI thread.

This is effectively delaying the intent processing, and detrimental to performance. warmup() should instead be broken down in tasks that yield the main thread in between, and are canceled by an incoming Intent.

See the attached trace. It was gathered by installing customtabs_benchmark_apk on a N5X running Android N, and running the following script:


#!/bin/bash

PACKAGE_NAME="org.chromium.customtabs.test"

adb root

adb shell am force-stop com.google.android.apps.chrome
adb shell am force-stop $PACKAGE_NAME
adb shell "echo 3 > /proc/sys/vm/drop_caches"

sleep 3

URL=$1

adb shell am start -n ${PACKAGE_NAME}/.MainActivity \
  --es "url" "$URL" \
  --ez "warmup" "true" \
  --ei "delay_to_launch_url" "100"


This will wait 100ms between warmup() and the intent dispatch.
On the trace, there is a 1+s delay between warmupInternal() start and AsyncInitializationActivity.onCreate().

Chrome command line parameters:
--trace-startup --trace-startup-duration=20 --custom-tabs-log-service-requests

From logcat:
07-20 14:02:58.052  7759  7759 W cr_ChromeConnection: Service#onBind() = true, Calling UID = 10433
07-20 14:02:58.061  7759  7772 W cr_ChromeConnection: newSession() = true, Calling UID = 10355
07-20 14:02:58.138  7740  7740 W CUSTOMTABSMEMORY: OnServiceConnected,25547,5900
07-20 14:02:58.167  7759  7772 W cr_ChromeConnection: warmup() = true, Calling UID = 10355
[...]
07-20 14:02:58.341   878   892 I ActivityManager: START u0 {act=android.intent.action.VIEW dat=https://www.android.com/... pkg=com.google.android.apps.chrome cmp=com.google.android.apps.chrome/.Main (has extras)} from uid 10355 on display 0
[...]
07-20 14:02:59.110   878  3401 I ActivityManager: START u0 {act=android.intent.action.VIEW dat=https://www.android.com/... flg=0x800000 pkg=com.google.android.apps.chrome cmp=com.google.android.apps.chrome/org.chromium.chrome.browser.customtabs.CustomTabActivity (has extr
as)} from uid 10433 on display 0



 
trace.json.gz
2.8 MB Download

Comment 1 by lizeb@chromium.org, Jul 21 2017

From review comments:

One is to stop processing everything at once, and stop all warmup() tasks when we get the intent.

In the case where warmup() has enough time, this should not impact the overall time taken by warmup() beyong the overhead of posting a few tasks, which is negligible compared to 1.5s of CPU. Beyond that, no impact on startup time.

Comment 2 by lizeb@chromium.org, Jul 21 2017

See a trace attached with the patch applied. Time to ChromeLauncherActivity is shorter.
trace_-.trace_split_tasks.json.gz
2.8 MB Download
Project Member

Comment 3 by bugdroid1@chromium.org, Jul 27 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/7f304d3424de837a2875c387c5abf97354910b9e

commit 7f304d3424de837a2875c387c5abf97354910b9e
Author: Benoit Lize <lizeb@chromium.org>
Date: Thu Jul 27 12:20:10 2017

customtabs: Chain warmup() tasks like for Browser intialization.

Before this patch, warmup() is a single UI thread task. This is
necessary for browser intialization since we don't want to process an
intent from a half-started state. However, some initialization can be
broken down into tasks. To make a difference though, these tasks have to
be chained, that is the next one should be posted when the current one
completes, in order to yield the UI thread to a task posted in the
meantime.

This was already done in ChromeBrowserInitializer, so we extract it to a
common class. In addition, cancel the remaining tasks when an intent is
handled, as the later warmup() tasks are then detrimental to performance.

Change-Id: Ifd419cbe3971a06677b0bfda06001092d22fbae5
Bug:  746936 
Reviewed-on: https://chromium-review.googlesource.com/567188
Reviewed-by: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Reviewed-by: Yusuf Ozuysal <yusufo@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#489903}
[modify] https://crrev.com/7f304d3424de837a2875c387c5abf97354910b9e/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
[add] https://crrev.com/7f304d3424de837a2875c387c5abf97354910b9e/chrome/android/java/src/org/chromium/chrome/browser/init/ChainedTasks.java
[modify] https://crrev.com/7f304d3424de837a2875c387c5abf97354910b9e/chrome/android/java/src/org/chromium/chrome/browser/init/ChromeBrowserInitializer.java
[modify] https://crrev.com/7f304d3424de837a2875c387c5abf97354910b9e/chrome/android/java_sources.gni
[modify] https://crrev.com/7f304d3424de837a2875c387c5abf97354910b9e/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
[modify] https://crrev.com/7f304d3424de837a2875c387c5abf97354910b9e/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java
[modify] https://crrev.com/7f304d3424de837a2875c387c5abf97354910b9e/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsTestUtils.java
[add] https://crrev.com/7f304d3424de837a2875c387c5abf97354910b9e/chrome/android/javatests/src/org/chromium/chrome/browser/init/ChainedTasksTest.java

Comment 4 by lizeb@chromium.org, Feb 20 2018

Status: Fixed (was: Started)

Sign in to add a comment