Apply minor optimizations to scope parsing - #1438
Merged
Merged
Conversation
sirosen
requested review from
MaxTueckeGlobus,
aaschaer,
ada-globus,
derek-globus,
kurtmckee and
m1yag1
as code owners
September 25, 2026 15:50
Merging this PR will improve performance by 12.19%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_deeply_nested_object_encoding[1w-5d] |
177.1 µs | 155.9 µs | +13.58% |
| ⚡ | test_wide_scope_parsing[10000] |
568.3 ms | 509.6 ms | +11.52% |
| ⚡ | test_wide_scope_parsing[5000] |
283.4 ms | 254.2 ms | +11.48% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing sirosen:optimize-scope-construction (5920be6) with main (8ac1169)
1. Don't build methods we don't need on an internal dataclass
(ScopeTreeNode) by setting `repr=False, eq=False, order=False` for
that class
2. Replace `any(<containment checking generator>)` with a regex search
in Scope __post_init__.
sirosen
force-pushed
the
optimize-scope-construction
branch
from
September 25, 2026 19:56
615b68d to
3bcd807
Compare
kurtmckee
requested changes
Sep 25, 2026
Co-authored-by: Kurt McKee <contactme@kurtmckee.org>
kurtmckee
approved these changes
Sep 25, 2026
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.
Don't build methods we don't need on an internal dataclass (ScopeTreeNode) by setting
repr=False, eq=False, order=Falsefor that classReplace
any(<containment checking generator>)with a regex search in Scope__post_init__.(1) is barely measurable. I ran some timeit benchmarking on a simplified example and found that it improves import time by ~100μs (0.1ms) on python3.13.
It will take many import cycles for this to pay the time and energy cost of benchmarking it.
I share it partly as a bit of information learned: we can optimize dataclass definition time, but it's not going to offer a significant win today.
(2) should be noticeable. I observed improvements that were small but measurable in our existing benchmarks.
I also think the regex check is at least as readable as the generator expression it replaces.