Skip to content

perf: cache size and jump_target from first pass in to_bytecode#200

Merged
MatthieuDartiailh merged 1 commit into
MatthieuDartiailh:mainfrom
P403n1x87:perf/cache-jump-targets
May 22, 2026
Merged

perf: cache size and jump_target from first pass in to_bytecode#200
MatthieuDartiailh merged 1 commit into
MatthieuDartiailh:mainfrom
P403n1x87:perf/cache-jump-targets

Conversation

@P403n1x87

Copy link
Copy Markdown
Contributor

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.

Profiling data

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)

Benchmark runs

Range Avg
Before 214–226 r/s ~221 r/s
After 224–232 r/s ~229 r/s

~3.5% throughput improvement.

`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-commenter

codecov-commenter commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.40%. Comparing base (e5d1d74) to head (fa35a70).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@P403n1x87 P403n1x87 marked this pull request as ready for review May 22, 2026 10:05
@MatthieuDartiailh MatthieuDartiailh merged commit bd74da9 into MatthieuDartiailh:main May 22, 2026
10 checks passed
@P403n1x87 P403n1x87 deleted the perf/cache-jump-targets branch May 22, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants