Cap the direct-borrow scan at max builtin arity (#546)#547
Merged
InauguralPhysicist merged 1 commit intoJul 11, 2026
Conversation
The post-call direct-borrow heuristic scanned the ENTIRE argument list comparing item pointers against the builtin's result. For multi-arg calls that list is the small VM-packed temp, but a single list argument is the caller's own list — so `len of xs` cost O(len(xs)) per call and the idiomatic `loop while i < (len of xs):` was quadratic: ~520x slower than a hoisted length at 88k elements (surfaced by DeslanStudios rendering 44.1 kHz audio buffers). A borrowing builtin can only return a child it actually read, and every builtin reads its argument vector at small fixed indices (max arity in the registry is 7), so items past a small cap can never be the borrowed result. The scan is factored into vm_borrow_scan (shared by CASE(CALL), jit_helper_call, and OP_DISPATCH) and capped at 8. The borrow contract the cap must preserve is pinned in tests/test_call_semantics.eigs: coalesce/dict_set returning a direct child of a raw list VARIABLE (not just packed temps), a borrowed child of a dying temporary argument, and a >cap-length raw list with the borrow at index 0. 88k-iteration len-in-condition loop: 5,033ms -> 17.5ms. Full release suite: 2731/2731. Closes #546 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EKawAe121NNznQPXKiyxRf
This was referenced Jul 11, 2026
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.
The post-call direct-borrow heuristic scanned the ENTIRE argument list comparing item pointers against the builtin's result. For multi-arg calls that list is the small VM-packed temp, but a single list argument is the caller's own list — so
len of xscost O(len(xs)) per call and the idiomaticloop while i < (len of xs):was quadratic: ~520x slower than a hoisted length at 88k elements (surfaced by DeslanStudios rendering 44.1 kHz audio buffers).A borrowing builtin can only return a child it actually read, and every builtin reads its argument vector at small fixed indices (max arity in the registry is 7), so items past a small cap can never be the borrowed result. The scan is factored into vm_borrow_scan (shared by CASE(CALL), jit_helper_call, and OP_DISPATCH) and capped at 8.
The borrow contract the cap must preserve is pinned in tests/test_call_semantics.eigs: coalesce/dict_set returning a direct child of a raw list VARIABLE (not just packed temps), a borrowed child of a dying temporary argument, and a >cap-length raw list with the borrow at index 0.
88k-iteration len-in-condition loop: 5,033ms -> 17.5ms. Full release
suite: 2731/2731.
Closes #546
Claude-Session: https://claude.ai/code/session_01EKawAe121NNznQPXKiyxRf
What does this PR do?
Checklist
make testpasses locallydocs/BUILTINS.mddocs/STDLIB.md