perf(py): index Python imports in runtime venvs - #1466
Draft
zbarsky-openai wants to merge 1 commit into
Draft
zbarsky-openai wants to merge 1 commit into
zbarsky-openai wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
jbedard
marked this pull request as draft
August 19, 2026 17:14
jbedard
force-pushed
the
main
branch
2 times, most recently
from
August 25, 2026 18:24
b25e5ec to
25d3b44
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes are visible to end-users: yes
Adds opt-in indexed imports for private runtime virtual environments:
The existing physical layout remains the default. Public virtual environments
stay physical, and individual binaries or tests can opt out with
indexed_imports = False.How Python finds imports
For
import foo, Python's default finder searchessys.pathuntil it findsthe directory that owns
foo. A normal virtual environment collects installedpackages under one
site-packagesdirectory, letting Python use the filesystemto find each package directly.
rules_pyrecreates that directory with package symlinks for every binary andtest. If many targets share the same wheels, the number of projection actions
grows with the number of targets multiplied by the number of packages.
First-party import roots can also make
sys.pathunnecessarily large.What changes
Each indexed binary or test adds one build action that records which wheel or
first-party directory owns each import. A
.pthfile registers a finder onsys.meta_path; that finder looks up the owner and delegates loading toPython's existing import machinery. The action consumes declared artifact
paths without reading source contents.
Wheel metadata and RECORD parsing identify safe package projections while
preserving collision policy, package metadata, namespace packages,
pkgutil.extend_path, executable.pthfiles, native extensions, consolescripts, and PEP 427 data-file handling. Packages that require the existing
physical behavior retain their projections or whole-wheel fallbacks.
Source-wheel build tools keep physical environments. Filesystem-based
typecheckers, IDE integrations, and programs that copy
sys.pathinto a newinterpreter can use public virtual environments or
indexed_imports = False.In a representative large repository, the compatibility-preserving
configuration registered 56% fewer actions, reduced analysis-only build
wall time by 7%, and reduced peak process memory by 6%. A fully
indexed configuration reached 74% fewer actions when filesystem-only
consumers were also virtualized. Building an index from roughly 37,000 input
records took approximately 127 ms including Python interpreter startup.
Test plan
54 focused Bazel tests cover import-index generation, wheel collision
resolution, wheel metadata and exclusions, PEP 427 data files, legacy namespace
packages, indexed private virtual environments, unchanged public environments,
and per-target opt-outs.