-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Two small wins in the VM dispatch loop
1. Guard close_upvalues with an is_empty() check
Every Return unconditionally calls close_upvalues(frame_pointer), which iterates self.open_upvalues. For functions that capture no variables (like fib), this list is always empty — the loop body never executes but the iteration still occurs on every return.
Fix:
if !self.open_upvalues.is_empty() {
self.close_upvalues(frame_pointer);
}2. Avoid empty Vec allocation for upvalues in non-closure frames
dispatch_call_with_memo constructs a ClosureFunction for compiled functions:
Function::Compiled(f) => ClosureFunction {
prototype: f,
upvalues: vec![], // heap allocation even when empty
},vec![] may allocate (depending on the allocator). For functions with no captured variables this allocation is immediately wasted.
Fix options:
- Use
Vec::new()instead ofvec![]—Vec::new()is guaranteed not to allocate until the first push. - Or introduce a
CompiledFramevariant inCallFramethat doesn't have an upvalues field at all, avoiding the field entirely for non-closures.
Neither change is individually dramatic, but both are zero-risk and free given that fib makes ~636K calls.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels