From abec49b0c7f8ed22b3564dd68fa8e8c398c23c1b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 20 Aug 2026 05:00:42 +0000 Subject: [PATCH] Optimize VM instruction fetch by removing redundant array lookup Replaced a deep array lookup (`self.module.functions[...].chunk.instructions[ip].operands`) with a direct borrow from the existing instruction reference (`inst.operands.as_slice()`). This reduces bounds checking and pointer chasing in the hot path of the VM loop. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- .jules/bolt.md | 3 +++ runtime/vm/src/executor.rs | 7 +------ 2 files changed, 4 insertions(+), 6 deletions(-) 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();