Repository navigation
perf(comp): parameters a cycle passes along unchanged go as one node - #36
Draft
nicolas-abril wants to merge 1 commit into
Draft
nicolas-abril wants to merge 1 commit into
nicolas-abril wants to merge 1 commit into
Conversation
nicolas-abril
force-pushed
the
opt/wide-pin
branch
from
November 25, 2026 21:20
56be7be to
380dbad
Compare
nicolas-abril
added a commit
that referenced
this pull request
Dec 1, 2026
The one conflict: #36's wide-pin and this branch both mark HOT a spin whose single source site became several through copies (grp_defs' copies there, the closure pass's here); both rules and their notes kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Parameters of words alone (scalars, enums, records without boxes) that every call inside a cycle of defs passes a parameter of the caller as it is are a group, when the cycle has a call inside it that is not a tail and they hold 8 words or more where the cycle forks inside (20 where it does not: there each read's load sits on the chain of calls). Each def of the cycle that holds the group gets a copy, d~grp, whose first grouped parameter takes a node of all their words and the others no word; reads load off the node (GRP_KEEP holds words handed to a loop in place). The defs as written take the words: a call from outside costs nothing, and the def's first call into the cycle builds the node, which its owner frees once nothing reads it. Calls inside the cycle go to the copies, so frames, forks and tasks hold the group as one word. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 380dbad)
nicolas-abril
force-pushed
the
opt/wide-pin
branch
from
December 1, 2026 21:55
d0ddb81 to
068a264
Compare
nicolas-abril
added a commit
that referenced
this pull request
Dec 1, 2026
…33, #34, #36, #39, #44, #61-#68): record their heads Each is a port onto main of integration's own branch, its content already here (integration keeps the original commits; the ports add type fixes, line wraps, moved pieces and #68's book_passes, applied in the previous commit). Groups: #61 (#9 #11 #15 #32 #41 #42), #62 (#26 #56), #63 (#48 #50 and compile-time), #64 (#19 #20 #45), #67 (#55 #58), #68 (#54); par-defer (#43) is now part of #34, lazy-startup's parts are in #16 and #34. This merge records their heads (-s ours: no content change). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
On main (
6180be5b)This PR is a port onto main, on
main: 1 commit of its own, with no integration history (head068a264f).Port notes
def_treereduced to leaves and shape (A call whose arguments a recursion never changes is computed once, in a copy of the def that carries the value #21's),def_calls/def_reach_set/FL.calls(perf(comp): a statement's call unfolds into a def that is not flat #17's),FL.madewithtld_of's fallback (as in perf(comp): one specializer: a call copies its callee for the lambdas and constants it passes (replaces #31, #52, #2) #53), per-caller site counts (Defs that tail-call each other in a cycle run as one loop: a head's spin holds the other defs' bodies #22's), and only theHOTmacro with this PR's own HOT rule (perf(comp): forced inlining: a loop's large or looping spin calls are HOT, under a growth cap (squashes #13, #40) #59 has the others).Checks
io_tcp_text_residueon the interpreter lane, a TCP test that is flaky on the cluster; it passes locally, on this branch and on main.run/array_slabfails on main too).ttok -m gpt-3.5-turbo) over main, which is at 65,989 of the 66,000 cap.Performance was measured on integration when this change merged there (see the original description or the replaced PRs); it has not been re-measured on main.
Original description (written for integration)
Stacked on
opt/integration(09d002f). One commit;comp.ts+4,909 ttok (99,999 to 104,908). Measured on one Mac (M4) under the shared lock; perf gate on the cluster.What
Every flat value is one word per field, so a recursion that passes 20 words along unchanged copies them into every frame, register set and task. This passes such parameters as one word:
grp_slots). The cycle needs a call inside it that is not a tail call (a tail loop already keeps the words in registers). The group needs 8 words or more if the cycle forks inside itself, 20 if it doesn't: there, each read's extra load sits on the chain of calls, which is why a 16-word serial walk is left as words. A slot is the set of parameters that the calls join together, so two defs may pass the values in different positions.d~grp. In the copy, the first grouped parameter takes a heap node of all the words and the others take no word; reads load off the node. The node is a raw word, so refcounts and borrowing never see it. Calls inside the cycle go to the copies (grp_route), so frames, forks and tasks hold the group as one word.GRP_KEEP(an emptyasmon the host), because clang otherwise compiles the loop differently around loaded values (+1.5% instructions in quickhull). A spin called from one site in the source is now called from a def and its copy, so the call is markedHOTto keep clang's single-site inlining (kmeans lost 1.9% without it). A def and its copy share their lends (raytracer's BVH stays borrowed).Effect
Microbenchmarks (16 separate U32s unless noted; a fork tree of 2^25 leaves; integration → this PR):
Cost: a loop that hands 12 fresh words to a forked recursion 2M times runs 1.00x the cycles at depth 0, 1.14x at depth 1, 0.94x at depth 2 and 0.71x at depth 3.
Benchmarks. Of the 244 programs in bend-benchmarks, 5 change C. All print
expected.txt(the parallel ports also at 10 threads). Cycles, median of 5:rcol's Nat and 8-word LUTpfold's 8 centroidsflags' flag and two linesrender's 12-word cameraPerf gate: this PR passed 111 and 113 of 124, against 113 on
opt/integration, within the gate's run-to-run spread.Checks
opt/integration's, and no existing test's C changes.tests/run/param_group.bend: serial and forked groups; two defs passing the words in another order; records, a record of records with a tag, a constant record, and a record stored in a list; a matched flag; closures that run inside the cycle and after it returns; a word or a record that one call changes (it stays words); entries at depths 0 and 1, from a tail call, from a fork and inside a walk; a loop handed grouped words; bang calls. It passes at 1 and 8 threads and with the GPU on and off, with 0 live words under-DBEND_POISON.An earlier version also passed 12-word records through a borrowed box. It went, because groups do the same job without touching refcounts or borrowing. Its history is on
opt/wide-pin-history.Updates
🤖 Generated with Claude Code