Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support persistent worker for aar extractors #18496

Closed

Conversation

SupSaiYaJin
Copy link

This PR supports persistent worker for Android aar extractors, it'll significantly improve the aar extractors performance especially in the first time compilation without cache.
It's not enable by default, can use flag build --experimental_persistent_aar_extractor=true to enable it.

using worker:
image
not using worker:
image

@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label May 25, 2023
@sgowroji sgowroji added the team-Android Issues for Android team label May 25, 2023
@SupSaiYaJin SupSaiYaJin force-pushed the aar-extractor-worker branch 2 times, most recently from d4379ae to aa06c30 Compare May 31, 2023 12:29
Copy link
Contributor

@ted-xie ted-xie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few general comments:

  1. If we're adding a new execution mode for aar extraction, we need to add a test for it. Please see how other tools (i.e. busybox, desguar, dex) test their worker/multiplex worker functionality. I think a lot of those tests are in src/test/bazel/android/android_integration_test.sh.
  2. Please add more comments describing what your changes are doing, since behavior around execution strategy is critical functionality, and we want the logic to be as clear as possible.
  3. In general the json_worker_wrapper.py file seems quite verbose and low-level for a python program. I would imagine that a lot of this functionality can be refactored to be more pythonic.

tools/android/json_worker_wrapper.py Outdated Show resolved Hide resolved
tools/android/json_worker_wrapper.py Outdated Show resolved Hide resolved
tools/android/json_worker_wrapper.py Outdated Show resolved Hide resolved
tools/android/json_worker_wrapper.py Outdated Show resolved Hide resolved
tools/android/json_worker_wrapper.py Outdated Show resolved Hide resolved
third_party/py/abseil/absl/app.py Outdated Show resolved Hide resolved
@ted-xie
Copy link
Contributor

ted-xie commented May 31, 2023

I'm also curious about what the cumulative time savings of all aar extraction actions is for your change. Your screenshot shows a 758 -> 15 ms wall time reduction, which is indeed impressive, but I think that's just for a single action.

@SupSaiYaJin
Copy link
Author

SupSaiYaJin commented Jun 1, 2023

I'm also curious about what the cumulative time savings of all aar extraction actions is for your change. Your screenshot shows a 758 -> 15 ms wall time reduction, which is indeed impressive, but I think that's just for a single action.

It saves nearly 100 seconds for the first-time compilation without cache. It had nearly 2000 extractor actions executed for my project, each of which saved nearly 500ms. I run it on a 10-core CPU, 500ms * 2000 / 10 ≈ 100s

Copy link
Contributor

@ted-xie ted-xie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor changes requested for this iteration. Looking much better.

tools/android/json_worker_wrapper.py Show resolved Hide resolved
tools/android/json_worker_wrapper.py Outdated Show resolved Hide resolved
third_party/py/abseil/absl/app.py Outdated Show resolved Hide resolved
src/test/shell/bazel/android/aar_integration_test.sh Outdated Show resolved Hide resolved
tools/android/BUILD.tools Show resolved Hide resolved
tools/android/BUILD Show resolved Hide resolved
@SupSaiYaJin SupSaiYaJin requested a review from ted-xie June 6, 2023 08:44
@ted-xie ted-xie added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Jun 6, 2023
@SupSaiYaJin
Copy link
Author

When will this PR be merged? Do I need to do anything else? :) @ted-xie

@sgowroji
Copy link
Member

sgowroji commented Jun 7, 2023

Hi @SupSaiYaJin, I will update you once it's merged. Thanks!

Copy link
Contributor

@ted-xie ted-xie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SupSaiYaJin, we ran into a couple linting issues while importing these. Could you take a look at the comments and adress them? Thank you!

tools/android/json_worker_wrapper.py Outdated Show resolved Hide resolved
tools/android/json_worker_wrapper.py Outdated Show resolved Hide resolved
@ted-xie
Copy link
Contributor

ted-xie commented Jun 13, 2023

@SupSaiYaJin Stepping back a little, I'm curious what are your thoughts on using a faster unzip implementation, versus implementing worker support for AAR extraction. We could use this as an opportunity to refactor AAR extraction in general to use a different zip inflate implementation, versus adding significant complexity (new flag, new execution strategy) to AAR extraction which in general is not supposed to be the bottleneck on build workflows.

@SupSaiYaJin
Copy link
Author

@ted-xie What would this implementation look like? If it also needs to start a new process to run, I think it still needs to run in worker mode.

@Pavank1992 Pavank1992 added awaiting-review PR is awaiting review from an assigned reviewer awaiting-user-response Awaiting a response from the author and removed awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally labels Jun 16, 2023
@SupSaiYaJin SupSaiYaJin requested a review from ted-xie June 29, 2023 02:46
@ted-xie
Copy link
Contributor

ted-xie commented Jul 11, 2023

Sorry, I missed the notification for this PR.

What would this implementation look like?

Jar/aar extraction is basically just unzip; if you choose a faster unzip executable, the combined process call + execution time may be less than the performance gain from worker mode.

If it also needs to start a new process to run, I think it still needs to run in worker mode.

Much of the current performance penalty for this action comes from having to spin up a java process, i.e. the entire JVM needs to come alive. The same limitation does not exist for unzip tools written in a non-runtime language.

@SupSaiYaJin
Copy link
Author

@ted-xie We can use worker for now and do it in the future, I think it's a good idea :).
Anything else I should do with this pr?

@ted-xie ted-xie removed awaiting-review PR is awaiting review from an assigned reviewer awaiting-user-response Awaiting a response from the author labels Aug 2, 2023
@ted-xie ted-xie added the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Aug 2, 2023
@sgowroji
Copy link
Member

sgowroji commented Aug 3, 2023

Hi @SupSaiYaJin , Could you please update the latest changes from master into the branch as it is awaiting to merge. Thanks!

@SupSaiYaJin
Copy link
Author

@sgowroji done

copybara-service bot pushed a commit that referenced this pull request Aug 4, 2023
Unblocks lint-related problems in #18496.

PiperOrigin-RevId: 553886150
Change-Id: Ie7f5d369def2b5556fefe24e78e7a57d94921766
@SupSaiYaJin
Copy link
Author

@ted-xie done

@SupSaiYaJin
Copy link
Author

@ted-xie Do you use any instant messaging apps? I would like to have a more in-depth conversation with you. Could we add each other as friends?

@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Android Issues for Android team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants