Skip to content

VmCallable::call() clones globals on every invocation #111

@timfennis

Description

@timfennis

Problem

VmCallable::call() takes ownership of the globals slice on every call:

pub fn call(&self, args: Vec<Value>) -> Result<Value, VmError> {
    Vm::call_function(self.function.clone(), args, self.globals.to_vec())
}

self.globals.to_vec() clones the entire globals slice (O(g) allocations) on every call. This is the dominant bottleneck for HOF-heavy programs once the Sequence-bridge conversions are eliminated (see the Sequence → VmNative migration). For filter(bigList, f) with n elements and g globals, the current cost is O(n × g).

Fix

Thread &[Value] through Vm::call_function rather than taking ownership. VmCallable already holds globals: &'a [Value], so no structural change to VmCallable is needed — only Vm::call_function's signature and internal usage need updating.

// Before:
pub fn call_function(function: Function, args: Vec<Value>, globals: Vec<Value>) -> Result<Value, VmError>

// After:
pub fn call_function(function: Function, args: Vec<Value>, globals: &[Value]) -> Result<Value, VmError>

Impact

Blocks the full performance benefit of the Sequence → VmNative migration. Once bridge conversions are gone, globals.to_vec() becomes the next dominant cost in HOF loops.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions