perf(rt): adopt PreparedCall in reduce's fold loops - #727
Open
mparrett wants to merge 3 commits into
Open
Conversation
5 tasks
mparrett
force-pushed
the
perf/vm-prepared-call-reduce
branch
from
August 12, 2026 05:55
08e1da3 to
239cfff
Compare
mparrett
force-pushed
the
perf/vm-prepared-call-reduce
branch
from
August 12, 2026 16:28
b372353 to
999f0bd
Compare
mparrett
force-pushed
the
perf/vm-prepared-call-reduce
branch
from
August 12, 2026 19:44
999f0bd to
42f4115
Compare
mparrett
force-pushed
the
perf/vm-prepared-call-reduce
branch
3 times, most recently
from
August 13, 2026 16:40
a11721a to
a8e6d4a
Compare
mparrett
force-pushed
the
perf/vm-prepared-call-reduce
branch
from
August 14, 2026 00:03
a8e6d4a to
43e9ad3
Compare
reduce's four fold loops (ArrayVector, Range, chunked, and linear seq) each invoked the reducing fn through ec.Invoke, paying resolution, frame-pool mutex traffic, and frame init once per element. Resolve the reducer once per fold with PrepareCall and reuse its frame; non-bytecode and variadic reducers keep the reused-fargs ec.Invoke fallback. Adds PreparedCall.Call2 for binary callables — deliberately introduced with its first consumer. On (reduce (fn [a x] (+ a x)) 0 (range 1000000)), darwin/arm64, interleaved mins: 50.5 ms vs 67.3 on the base branch and ~58.7 on v1.12.2 — the second adopter to land below the release baseline. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The guard added on the base branch admits only arities a CallN entry point can populate; Call2 lands here, so admit arity 2 and pin it with a repeated-invocation test. Also refresh generated.sums for this branch's own native_prims.go edits. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Nothing tied the invocation method to the preparation: Call2 on a unary preparation panicked writing args[1], and Call1 on a binary one invoked bytecode with a stale or Go-nil second slot. CallN now returns an ExecutionError on mismatch; the check is one predictable compare per call (interleaved reduce micro unchanged: 39.4ms base / 39.0ms head mins). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mparrett
force-pushed
the
perf/vm-prepared-call-reduce
branch
from
August 14, 2026 23:16
43e9ad3 to
f688abc
Compare
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.
Second adopter from #720, stacked on the PreparedCall PR.
reduce's four fold loops — ArrayVector, Range, chunked seq, and linear seq — each invoked the reducing fn throughec.Invoke, paying per-element resolution, frame-pool mutex traffic, and frame init. Resolve the reducer once per fold withPrepareCalland reuse its frame; non-bytecode and variadic reducers keep the reused-fargsfallback in all four loops.Adds
PreparedCall.Call2for binary callables, introduced with its first consumer rather than ahead of one.PrepareCall's arity guard widens to admit 2, and eachCallNvalidates against the prepared arity — a mismatch returns an error instead of panicking or invoking with unpopulated argument slots.Measured on
(reduce (fn [a x] (+ a x)) 0 (range 1000000)), darwin/arm64, interleaved mins: 50.5 ms vs 67.3 on the base branch and ~58.7 on v1.12.2 — the second adopter to land below the release baseline. Sameperf-repeatcaveat as the base PR: the micro families don't route throughrtreduce, so the lane is a regression guard; the e2e number is the claim.New tests:
Call2repeated invocation,CallN/arity mismatch errors, unsupported-arity rejection. Suites green:pkg/vm,pkg/rt,test/.