refactor: defer zip manifest building to execution phase to improve analysis phase performance by tobyh-canva · Pull Request #3381 · bazel-contrib/rules_python

@tobyh-canva

@tobyh-canva mentioned this pull request

Oct 27, 2025

@tobyh-canva tobyh-canva changed the title zip file analysis optimisation: alternate starlark-only approach perf: improve analysis performance by for py_binary and py_test rules

Nov 9, 2025

@rickeylev

@rickeylev rickeylev changed the title perf: improve analysis performance by for py_binary and py_test rules refactor: defer zip manifest building to execution phase to improve analysis phase performance

Nov 9, 2025

@rickeylev

@rickeylev

@rickeylev

rickeylev

@tobyh-canva tobyh-canva deleted the create-zip-file-analysis-optimisations-3 branch

November 11, 2025 22:59

aignas added a commit to aignas/rules_python that referenced this pull request

Dec 6, 2025
Looking at the investigation in bazel-contrib#3381, it seems that we are calling
the startswith many times and I wanted to see if it would be possible
to optimize how it is done.

I also realized that no matter what target we have, we will be calling
the function once with a `__init__.py` path and we can inline this case
as a separate if statement checking for equality instead, which Starlark
optimizer should understand better.

Before this PR for every executable target we would go through the
`legacy_external_runfiles and "__init__.py".startswith("external")` and
this PR eliminates this.

Related to bazel-contrib#3380 and bazel-contrib#3381

github-merge-queue bot pushed a commit that referenced this pull request

Dec 7, 2025
)

Looking at the investigation in #3380, it seems that we are calling
the startswith many times and I wanted to see if it would be possible
to optimize how it is done.

I also realized that no matter what target we have, we will be calling
the function once with a `__init__.py` path and we can inline this case
as a separate if statement checking for equality instead, which Starlark
optimizer should understand better.

Before this PR for every executable target we would go through the
`legacy_external_runfiles and "__init__.py".startswith("external")` and
this PR eliminates this.

Related to #3380 and #3381

github-merge-queue bot pushed a commit that referenced this pull request

Feb 15, 2026
This is the `py_wheel` counterpart to the analysis-time performance work
done
for `py_binary`/`py_test` in #3381 and #3442,   deferring depset
expansion to execution time.  Tested under Bazel 8.5.1 and 9.0.0.

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>