Skip to content

Commit cdfe5d3

Browse files
authored
Merge pull request #21 from Tcode-Motion/optimize-vm-fetch-decode-11168865889127833758
⚡ Bolt: Optimize VM instruction fetch by removing redundant array lookup
2 parents bab9110 + abec49b commit cdfe5d3

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

.jules/bolt.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 2026-08-19 - Removed redundant instruction array lookup in VM loop
2+
**Learning:** The inner loop of the VM interpreter (`execute_loop`) had an expensive, redundant deep indexing operation to fetch `inst_operands` which was already available on the `inst` reference. Re-fetching it via `self.module.functions[...].chunk.instructions[...].operands` adds unnecessary bounds checks and pointer chasing in the hottest part of the VM.
3+
**Action:** Always prefer using existing local references over redundant deep lookups, especially in tight loops like an interpreter fetch-decode-execute loop.

runtime/vm/src/executor.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ impl VM {
2828
let ip = frame.ip;
2929
frame.ip += 1;
3030

31-
let inst_operands = self.module.functions
32-
[self.frames.last().unwrap().function_idx as usize]
33-
.chunk
34-
.instructions[ip]
35-
.operands
36-
.as_slice();
31+
let inst_operands = inst.operands.as_slice();
3732

3833
// Diagnostics and tracing
3934
self.profiler.record_instruction();

0 commit comments

Comments
 (0)