Try to shrink onResourceLoaded() code size in webview / monochrome R.java |
||
Issue description
If you look at gen/clank/java/monochrome_apk__process_resources.srcjar, you can see R.java files contain methods like:
public static void onResourcesLoaded(int packageId) {
attr.allowShortcuts = (attr.allowShortcuts & 0x00ffffff) | (packageId << 24);
attr.ambientEnabled = (attr.ambientEnabled & 0x00ffffff) | (packageId << 24);
...
}
These are called by reflection from the framework when packagedId != 7f (the default):
https://github.com/android/platform_frameworks_base/blob/4b1a8f46d6ec55796bf77fd8921a5a242a219278/core/java/android/app/LoadedApk.java#L824
Rather than using aapt, we generate these from our own templates here:
https://cs.chromium.org/chromium/src/build/android/gyp/process_resources.py?q=process_resour+ce&sq=package:chromium&l=214
I'd like to try a couple ideas to reduce code size:
Idea #1: Use a variable "shiftedPackageId"
public static void onResourcesLoaded(int packageId) {
int shiftedPackageId = packageId << 24;
attr.allowShortcuts = (attr.allowShortcuts & 0x00ffffff) | shiftedPackagedId;
attr.ambientEnabled = (attr.ambientEnabled & 0x00ffffff) | shiftedPackagedId;
...
}
Idea #2: Use xor rather than masks
public static void onResourcesLoaded(int packageId) {
assert(attr.allowShortcuts >> 24 == 0x7f)
int packageIdTransform = (packageId ^ 0x7f) << 24;
attr.allowShortcuts = attr.allowShortcuts ^ packageIdTransform;
attr.ambientEnabled = attr.ambientEnabled ^ packageIdTransform;
...
}
To measure how much smaller this makes the code, we should build monochrome_public_apk with is_java_debug=false, and then list the uncompressed size of classes.dex via "unzip -lv apks/MonochromePublic.apk | grep classes"
,
Dec 6 2016
Related inheritance idea: https://bugs.chromium.org/p/chromium/issues/detail?id=671648
,
Dec 12 2016
Below is the result: Method Uncompressed Compressed Original 6349492 2759696 Variable 6337480 2758869 Xor 6333444 2759237
,
Dec 13 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/b10563e0715c0c61e503f5ef285c5a0652ae583f commit b10563e0715c0c61e503f5ef285c5a0652ae583f Author: zpeng <zpeng@chromium.org> Date: Tue Dec 13 18:22:22 2016 Shrink onResourcesLoaded() code size in webview/monochrome R.java. Shrinks code size in webview/monochrome R.java by rewriting the template for onResourcesLoaded(). Uses xor instead of masking to transform the fields. See attached bug link for discussion and details. BUG= 669137 Review-Url: https://codereview.chromium.org/2573613002 Cr-Commit-Position: refs/heads/master@{#438229} [modify] https://crrev.com/b10563e0715c0c61e503f5ef285c5a0652ae583f/build/android/gyp/process_resources.py
,
Dec 13 2016
,
Dec 14 2016
Nice! This showed up in the size graphs as a 25k size drop! https://chromeperf.appspot.com/report?sid=0092af7d0435c43fab71933e7702e7d63eb0e7e73e6aeb006141c156f4e69fa8&num_points=5&rev=438229 |
||
►
Sign in to add a comment |
||
Comment 1 by michaelbai@chromium.org
, Nov 28 2016