Commit 8bf35e4
authored
perf: avoid redundant validation in copy() and __iter__ (#193)
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%)1 parent 66584dc commit 8bf35e4
2 files changed
Lines changed: 6 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | 167 | | |
174 | 168 | | |
175 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
812 | 812 | | |
813 | 813 | | |
814 | 814 | | |
815 | | - | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
816 | 821 | | |
817 | 822 | | |
818 | 823 | | |
| |||
0 commit comments