New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 669137 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Dec 2016
Cc:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

Try to shrink onResourceLoaded() code size in webview / monochrome R.java

Project Member Reported by agrieve@chromium.org, Nov 28 2016

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"


 
sgtm, interested in the result.

Comment 3 by zpeng@chromium.org, Dec 12 2016

Below is the result:
Method	        Uncompressed	Compressed
Original	6349492	        2759696
Variable	6337480	        2758869
Xor	        6333444	        2759237
Project Member

Comment 4 by bugdroid1@chromium.org, 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

Comment 5 by zpeng@chromium.org, Dec 13 2016

Status: Fixed (was: Assigned)

Sign in to add a comment