refactor(core): get_zip_runfiles_path should call startswith less by aignas · Pull Request #3442 · bazel-contrib/rules_python

@aignas

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

gemini-code-assist[bot]

rickeylev

Merged via the queue into bazel-contrib:main with commit 9559b20

Dec 7, 2025

4 checks passed

@aignas aignas deleted the exp.aignas.get_zip_runfiles_path branch

December 7, 2025 14:17

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>