perf(py_wheel): defer depset expansion to execution time#3599
perf(py_wheel): defer depset expansion to execution time#3599rickeylev merged 3 commits intobazel-contrib:mainfrom
Conversation
Replace analysis-time depset.to_list() loop with Args.add_all(map_each=...) and ctx.actions.write(Args), deferring depset expansion to execution time. The old code built the input file list via string concatenation in a loop, which is O(n^2) in the total string length. For large py_wheel targets this dominated analysis time (~18s for ~18k transitive files in a production monorepo). Tested under Bazel 8.5.1 and 9.0.0. Add tests/py_wheel_performance/ with: - A correctness test verifying wheel contents (100 deps) - A scaling regression test (tagged manual) asserting analysis time grows linearly, not quadratically, with dep count (5k vs 10k deps) Scaling test results (5k vs 10k deps, best of 3): Before: 2825 ms / 8616 ms = 3.05x (quadratic) After: 502 ms / 776 ms = 1.55x (linear)
Summary of ChangesHello @bd-dstodolsky, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the performance of Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant performance improvement to the py_wheel rule by deferring depset expansion to execution time. The implementation correctly replaces an analysis-time depset.to_list() loop with Args.add_all(map_each=...), which is the recommended approach for handling large dependency sets in Bazel. The change is well-supported by a comprehensive new test suite that includes both correctness and scaling performance tests, ensuring the change is both safe and effective. The pull request is well-documented and the changes are excellent.
rickeylev
left a comment
There was a problem hiding this comment.
Thanks for the optmization, +1 to it in general.
This looks entirely AI generated, so I'm not looking at it particularly deeply.
Trim the PR description. It becomes the commit description, so it needs to be concise and relevant for future people reading through the commit log. If there's information to keep, post it as a comment.
Remove the tests that rely on timing. CI is not a reliable environment for performance tests.
Do not create shell tests that invoke bazel as a subprocess. Such integration tests are expensive and difficult to debug.
If any test is created, it should be an analysis test, using rules_testing, that verifies the args are passed to the action as a manifest file.
I'm fine with no tests here; how the content is passed is an implementation detail, so existing tests should verify correctness.
|
Thanks. Tests removed and comments shortened. Note the performance test was tagged manual so it would not run in CI, but happy to remove; I had originally done it just as a benchmark but then decided to convert to a test, but happy to eliminate. Quick review appreciated! |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks, looks good! |
This is the
py_wheelcounterpart to the analysis-time performance work donefor
py_binary/py_testin #3381 and #3442, deferring depsetexpansion to execution time. Tested under Bazel 8.5.1 and 9.0.0.