From d61ffd6ae4bd93522ff3635097cc16c3fe474d78 Mon Sep 17 00:00:00 2001 From: Ryan Daum Date: Sun, 14 Jan 2024 17:03:51 -0500 Subject: [PATCH] Missed the most important unnecessary .clone() in variable setting. 25-30% throughput improvement in for/range and list_append benches. --- crates/kernel/src/vm/activation.rs | 2 ++ crates/kernel/src/vm/exec_state.rs | 2 +- crates/kernel/src/vm/vm_execute.rs | 14 ++++---------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/crates/kernel/src/vm/activation.rs b/crates/kernel/src/vm/activation.rs index 223b418b..cd8b61f7 100644 --- a/crates/kernel/src/vm/activation.rs +++ b/crates/kernel/src/vm/activation.rs @@ -323,6 +323,8 @@ impl Activation { assert!(self.pc < self.program.main_vector.len(), "pc out of bounds"); let op = &self.program.main_vector[self.pc]; self.pc += 1; + // TODO: It would be nice to avoid the clone here, and hold a reference in the execution loop, but + // that leads to borrow issues. op.clone() } diff --git a/crates/kernel/src/vm/exec_state.rs b/crates/kernel/src/vm/exec_state.rs index 47ece204..33a069e3 100644 --- a/crates/kernel/src/vm/exec_state.rs +++ b/crates/kernel/src/vm/exec_state.rs @@ -205,6 +205,6 @@ impl VMExecState { /// Set the value of a local variable. #[inline] pub(crate) fn set_env(&mut self, id: &Name, v: Var) { - self.top_mut().environment.set(id.0 as usize, v.clone()); + self.top_mut().environment.set(id.0 as usize, v); } } diff --git a/crates/kernel/src/vm/vm_execute.rs b/crates/kernel/src/vm/vm_execute.rs index 7a04fcf4..e85cfdf0 100644 --- a/crates/kernel/src/vm/vm_execute.rs +++ b/crates/kernel/src/vm/vm_execute.rs @@ -426,13 +426,13 @@ impl VM { binary_bool_op!(state, <=); } Op::In => { - let lhs = state.pop(); - let rhs = state.pop(); + let (lhs, rhs) = (state.pop(), state.peek_top()); let r = lhs.index_in(&rhs); if let Variant::Err(e) = r.variant() { + state.pop(); return self.push_error(state, *e); } - state.push(r); + state.update(0, r); } Op::Mul => { binary_var_op!(self, state, mul); @@ -764,13 +764,7 @@ impl VM { continue; } Op::Exit { stack, label } => { - return self.unwind_stack( - state, - FinallyReason::Exit { - stack, - label, - }, - ); + return self.unwind_stack(state, FinallyReason::Exit { stack, label }); } Op::Scatter { nargs,