Skip to content

⚡ Bolt: Eliminate O(N) array cloning in loops and destructuring - #16

Merged
Tcode-Motion merged 2 commits into
mainfrom
bolt-perf-tuple-no-clone-12063508566212123643
Aug 18, 2026
Merged

⚡ Bolt: Eliminate O(N) array cloning in loops and destructuring#16
Tcode-Motion merged 2 commits into
mainfrom
bolt-perf-tuple-no-clone-12063508566212123643

Conversation

@Tcode-Motion

Copy link
Copy Markdown
Owner

💡 What:
Modified RuntimeValue::Tuple iteration in Statement::For to take ownership rather than .clone()ing all inner RuntimeValues. Modified eval_index_access in the interpreter to accept &RuntimeValue instead of owned RuntimeValue, avoiding full vector/map duplication on read operations (like indexing a[0]).

🎯 Why:
Techscript's RuntimeValue::Tuple stores an owned Vec<RuntimeValue>. Functions like eval_index_access previously required the caller to .clone() the entire structure just to read an element. Also, Statement::For blindly cloned the tuple elements during iteration even when iter_val was a temporary owned value that could be destructured.

📊 Impact:
Reduces memory allocation and execution overhead during loop initializations and array/map evaluations from O(N) to O(1) in the interpreter.

🔬 Measurement:
Run the benchmarking suite via cargo run --release --manifest-path Cargo.toml --bin tsc benchmark. Tuples and indexed operations should yield significant memory reductions.


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

This commit avoids expensive copying in `RuntimeValue::Tuple` destructuring and read-only accesses:
- `Statement::For` now takes ownership of the tuple elements instead of calling `.clone()` when iterating.
- `eval_index_access` signature was changed to take `&RuntimeValue` by reference. This eliminates deep clones of tuples, lists, and maps at various callsites, reducing O(N) overhead to O(1) reads for variable evaluations and chained member/index access.

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 08:43
@Tcode-Motion
Tcode-Motion merged commit b588ced into main Aug 18, 2026
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