perf(vm): borrow callee name in vec dispatch instead of allocating 🪢#155
Merged
Conversation
Both `dispatch_vec_call` and `dispatch_vec_call_dynamic` eagerly built an `Option<String>` for the callee's name on every call, but only read it inside the overload-not-found error branch and the `map_err` closure for `call_callback`. The success path threw it away. Same shape as the GetIterator fix in 87e2e1b. Borrow the name as `&str` from a stable source whose lifetime is independent of `&mut self`: - `dispatch_vec_call`: `scalars.first().and_then(|f| f.name())` — the slice is caller-owned, so the &str doesn't conflict with &mut self. - `dispatch_vec_call_dynamic`: resolve the first vec candidate once into a held `Rc<Object>`, then borrow its name. The resolve_var was already happening inside `callee_name()`; only the `.to_string()` is gone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dispatch_vec_callanddispatch_vec_call_dynamicboth eagerly built anOption<String>for the callee's name on every call, then only read it from rarely-taken error branches (the overload-not-foundErrand thecall_callbackmap_errclosure). The success path threw theStringaway. Same shape of bug as the GetIterator fix in #147.Changes
dispatch_vec_call: borrow&strdirectly fromscalars.first().and_then(|f| f.name()). The slice is a caller-owned parameter, so the borrow lifetime is independent of&mut selfand themap_errclosure can capture it freely.dispatch_vec_call_dynamic: resolve the first vec candidate once into a heldRc<Object>, then borrow&strout of it. Theresolve_varcall already happened inside the oldcallee_name(); the.to_string()is what's gone.Vm::callee_name()itself is kept — it's still used from the regularCallopcode's "no function found" error path, where the allocation is fine because we're already on an error path.Caveat — perf impact is barely measurable
vec_hot_loop(200k–2M(int,int) + (int,int)calls):≈1.01× — within noise.
perfconfirms ~13% of total time goes to malloc/free, but the eliminated allocation is one smallString(operator name like"+") per outer vec call, dwarfed byFunction::clone, the per-callVecallocations forarg_values/elem_args/results, and the finalRc::new(Object::Tuple(...)). Unlike the GetIterator case, there's no deep recursive walk being saved here.So this is more of a code-cleanliness/correctness fix (no wasted allocation on the hot path;
&strreads more naturally thanOption<String>) than a real perf win. Happy to drop it if you'd rather not carry the churn.🤖 PR description generated by Claude.