Skip to content

⚡ Bolt: Remove clone on VM instructions in execute loop - #18

Merged
Tcode-Motion merged 2 commits into
mainfrom
bolt/vm-optimization-execute-loop-9953887423283783221
Aug 18, 2026
Merged

⚡ Bolt: Remove clone on VM instructions in execute loop#18
Tcode-Motion merged 2 commits into
mainfrom
bolt/vm-optimization-execute-loop-9953887423283783221

Conversation

@Tcode-Motion

Copy link
Copy Markdown
Owner

I've removed the clone() operation that happened on every single iteration of the VM execute_loop when reading instructions. This operation was extremely expensive because BytecodeInstruction wraps a heap-allocated Vec<Operand>.

Instead, I decoupled it by directly copying the op enum and slicing operands. In addition, I guarded the debugger.trace_instruction call behind a boolean condition. This prevents self.stack.get_dump() from unneccesarily building a copy of the stack on every iteration.

Benchmarks showed an execution time drop from 1.55s to 0.81s (~45% speedup) on a naive Fibonacci implementation. The tests run cleanly and no semantic behaviors were altered.

I've also logged this finding in .jules/bolt.md to prevent similar performance regressions in the future.


PR created automatically by Jules for task 9953887423283783221 started by @Tcode-Motion

💡 What: Changed the VM's main `execute_loop` to avoid cloning `BytecodeInstruction` structs on every iteration, passing `op` and `operands` slice to match block and debugger.
🎯 Why: `BytecodeInstruction` can be expensive to clone because it contains a `Vec<Operand>`. The executor loop evaluates millions of instructions per second, so eliminating this clone significantly reduces memory allocations and garbage collection overhead. Added an explicit `is_enabled()` check before `self.debugger.trace_instruction` to avoid lazy allocation of `self.stack.get_dump()` during execution.
📊 Impact: Expected to reduce execution time for compute-heavy TechScript programs by ~45%. On a naive fibonacci(28) test, execution time dropped from 1.55s to 0.81s.
🔬 Measurement: Verified with `time tsc run fib.ts`. Ran full test suite to ensure correctness.

Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@Tcode-Motion
Tcode-Motion marked this pull request as ready for review August 18, 2026 13:42
@Tcode-Motion
Tcode-Motion merged commit 630c4a3 into main Aug 18, 2026
3 of 6 checks passed
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.

1 participant