perf: avoid redundant validation in copy() and __iter__#193
Merged
MatthieuDartiailh merged 1 commit intoMay 8, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #193 +/- ##
=======================================
Coverage 95.17% 95.17%
=======================================
Files 7 7
Lines 2032 2032
Branches 449 448 -1
=======================================
Hits 1934 1934
Misses 54 54
Partials 44 44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
BaseInstr.copy() previously reconstructed instructions via __init__, triggering the full _set → _check_arg validation chain on every copy even though the source instruction is already known to be valid. Replace with object.__new__ + direct slot assignment to bypass validation entirely. _BaseBytecodeList.__iter__ ran _check_instr on every yielded item, but Bytecode.__iter__ (which calls this via super()) was already doing the same check — a redundant double-validation on every iteration. Profiling shows: - Instr._check_arg own time: 7.85% → 3.13% (−4.72%) - BaseInstr._set own time: 2.57% → 1.37% (−1.20%) - _BaseBytecodeList.__iter__ eliminated (was 2.18%)
86cf482 to
40f07b3
Compare
Owner
|
LGTM I will merge when you mark this as ready. |
Contributor
Author
|
@MatthieuDartiailh open for review 🙏 |
MatthieuDartiailh
approved these changes
May 8, 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.
BaseInstr.copy()previously reconstructed instructions via__init__, triggering the full_set → _check_argvalidation chain on every copy even though the source instruction is already known to be valid. Replace withobject.__new__+ direct slot assignment to bypass validation entirely._BaseBytecodeList.__iter__ran_check_instron every yielded item, butBytecode.__iter__(which calls this viasuper()) was already doing the same check — a redundant double-validation on every iteration.The script used for validating the change does a round-trip decompile/recompile for 1 second:
Profiling shows the following own CPU time figures:
Instr._check_argBaseInstr._set_BaseBytecodeList.__iter__Throughput (number of iteration within the 1 second duration) goes from ~90 to ~105.