perf: cache size and jump_target from first pass in to_bytecode#200
Merged
MatthieuDartiailh merged 1 commit intoMay 22, 2026
Merged
Conversation
`ConcreteBytecode.to_bytecode` makes two passes over the instruction list. The first pass (finding jump targets) already calls `c_instr.get_jump_target(offset)` and `c_instr.size` for every instruction. The main loop then called both again — redundantly, at the same offsets. This change stashes `(size, jump_target)` per instruction into a list during the first pass and consumes it via an iterator in the main loop, eliminating all second calls to `get_jump_target` and `size`. | Hotspot | Before | After | |---|---|---| | `ConcreteBytecode.to_bytecode` own | 9.56% | 8.29% | | `ConcreteBytecode.to_bytecode` total | 19.55% | 15.55% | | `ConcreteInstr.get_jump_target` total | 2.74% | gone (< top 20) | | `ConcreteInstr.size` total | 1.30% | gone (< top 20) | | | Range | Avg | |---|---|---| | Before | 214–226 r/s | ~221 r/s | | After | 224–232 r/s | ~229 r/s | ~3.5% throughput improvement.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #200 +/- ##
=======================================
Coverage 95.39% 95.40%
=======================================
Files 7 7
Lines 2107 2110 +3
Branches 456 456
=======================================
+ Hits 2010 2013 +3
Misses 54 54
Partials 43 43 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
MatthieuDartiailh
approved these changes
May 22, 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.
ConcreteBytecode.to_bytecodemakes two passes over the instruction list. The first pass (finding jump targets) already callsc_instr.get_jump_target(offset)andc_instr.sizefor every instruction. The main loop then called both again — redundantly, at the same offsets.This change stashes
(size, jump_target)per instruction into a list during the first pass and consumes it via an iterator in the main loop, eliminating all second calls toget_jump_targetandsize.Profiling data
ConcreteBytecode.to_bytecodeownConcreteBytecode.to_bytecodetotalConcreteInstr.get_jump_targettotalConcreteInstr.sizetotalBenchmark runs
~3.5% throughput improvement.