diff --git a/.jules/bolt.md b/.jules/bolt.md index e69de29b..1592fa94 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-08-19 - Removed redundant instruction array lookup in VM loop +**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. +**Action:** Always prefer using existing local references over redundant deep lookups, especially in tight loops like an interpreter fetch-decode-execute loop. diff --git a/runtime/vm/src/executor.rs b/runtime/vm/src/executor.rs index 766d79eb..a800df31 100644 --- a/runtime/vm/src/executor.rs +++ b/runtime/vm/src/executor.rs @@ -28,12 +28,7 @@ impl VM { let ip = frame.ip; frame.ip += 1; - let inst_operands = self.module.functions - [self.frames.last().unwrap().function_idx as usize] - .chunk - .instructions[ip] - .operands - .as_slice(); + let inst_operands = inst.operands.as_slice(); // Diagnostics and tracing self.profiler.record_instruction();