⚡ Bolt: Eliminate O(N) array cloning in loops and destructuring - #16
Conversation
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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Modified
RuntimeValue::Tupleiteration inStatement::Forto take ownership rather than.clone()ing all innerRuntimeValues. Modifiedeval_index_accessin the interpreter to accept&RuntimeValueinstead of ownedRuntimeValue, avoiding full vector/map duplication on read operations (like indexinga[0]).🎯 Why:
Techscript's
RuntimeValue::Tuplestores an ownedVec<RuntimeValue>. Functions likeeval_index_accesspreviously required the caller to.clone()the entire structure just to read an element. Also,Statement::Forblindly cloned the tuple elements during iteration even wheniter_valwas 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