Repository navigation
perf(python): index importlib alias rebind checks instead of rescanning - #848
Merged
Merged
Conversation
importlibAliases checked every distinct alias against every statement in the file, building regexes per alias and statement, so the cost grew with aliases times statements. Repeated `import importlib as ilN` took 102ms at 100 aliases, 1.5s at 500 and 5.3s at 1000 (about 26KB, far under the size cap). A statement can only rebind a name it mentions, so index identifiers to statements once and check each alias against only the statements that contain it. The same checks run on those statements, so which aliases are dropped is unchanged. 1000 aliases now take about 20ms. The new test fails before this change (5.8s against a 1.5s budget) and also checks that a rebound alias is still dropped. Fixes #847
rowkav09
force-pushed
the
perf/python-importlib-alias-index
branch
from
October 5, 2026 06:10
5dd35cc to
76a3fca
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.
The importlib alias check compared every distinct alias against every statement in the file, building regexes each time, so the cost grew with aliases times statements. A file with many
import importlib as ilNlines took 102ms at 100 aliases, 1.5s at 500 and 5.3s at 1000, about 26KB and well under the size cap.I now index identifiers to statements once, and each alias only checks the statements that mention it. The same checks run on those statements, so which aliases get dropped is unchanged. 1000 aliases take about 20ms now.
The new test builds 1000 aliases, checks the right dynamic imports are credited and a rebound alias is still dropped, and has a 1.5s budget. On main it took 8.5s on my run and failed; with the change the Python adapter suite passes, 274/274.
Fixes #847.