Skip to content

perf(rt): a hungry drain splits the oldest fork a sequential task has open - #34

Draft
nicolas-abril wants to merge 16 commits into
mainfrom
opt/par-split
Draft

nicolas-abril wants to merge 16 commits into
mainfrom
opt/par-split

Conversation

@nicolas-abril

@nicolas-abril nicolas-abril commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

On main (6180be5b)

This PR is a port onto main, on main: 16 commits of its own, with no integration history (head cb7f45a9).

Port notes

Checks

  • Cluster gate (every test, every lane): 1885 / 1885 pass.
  • Locally: no new tsc errors against main, no new comp.ts lines over 80, its tests pass on the C and JS lanes (plus 40 lane runs of existing tests; run/array_slab fails on main too).
  • comp.ts: +6645 tokens (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)

Moved from bendlang#2255 (opened 2026-11-23); its 1 comment stay there.

2026-11-30 (3108eef5, test comment 58397c87; integration 8e737f36): a block's cell index is a u64 on the CPU, so a field's offset folds into the load. Mechanism of the E-core register effect left after a31ac97b: the M4's E-cores run fewer register writes per cycle when most of them go to registers of one parity (P-cores do not care). Hand edits of vss's leaf loop (a .s per variant, E-pinned 1-thread cycles, 3 nodes): renaming the loop's one temporary (the mov/bfi pair that builds each field's u32 index) from w19 to any even register (w2, w6, w20, w22, w24, w26) gives 0.948, to any odd one (w3, w5, w7) 1.000; moving the base register x9 to x10 changes nothing; the pair's own instructions don't matter (an lsl/orr in w19 is as slow); moving one more ALU result to an odd register costs +4%, one to an even register saves 4%. Counting FP destinations too, the slow loop writes about 18 odd and 10 even registers per iteration, the fast one about 14 and 14. A microbenchmark agrees (E-cores: 12 independent adds to one parity 4.3 cycles per iteration, alternating 3.1; integer adds next to FP adds of the same parity 5.5-6.0, of the other parity 2.2-4.3; P-cores level). So any change that moves the allocation can flip it. Fix: blk_ptr/blk_read/blk_write take a u64 index on the CPU (BlkIx; the device keeps u32). A cell index is below 2^31 (5-bit class), so at + j never wraps, and clang folds the field offset into the load: one add per element instead of a mov and a bfi per field, and the loop no longer depends on which registers it gets (the same edit by hand is 0.953 with any register).

  • Cluster (M4 minis), vs opt/integration 16dcd67, median of 9 x 3 jobs: ocaml-nbody-imm 10 threads 136.4 -> 127.8 ms (0.937; before 3587c883: 131.2), E-pinned 1 thread 0.929 cycles, 1/2/4 threads 0.997. msort, ocaml-nbody, ocaml-lu-decomp, osprey fib and pascal (bend-par), parallel-ml fib, bfs, delaunay, seam-carve, mcss, primes, tree-bitonic: level at 1/2/4/10 threads (within 1.5%; osprey fib 10 threads 0.95). All 244 programs print expected at 1 and 10 threads; 1-thread cycles geomean 0.998 (215, instructions 0.999), 10-thread wall 1.001 (98). Outliers rerun (3 x 9, then 5 x 15): interval-tree-old, mutual, reverb level; gcdsum, pfor and pfor/helpers at 10 threads within noise (their assembly is identical to integration's).
  • Not fixed: subset-sum's 1-thread +3.5%. It is not this effect: E-pinned it is level, and it is on P-cores. Calling the clear loop out of line in pfor's fork segment still removes it (0.964); it is not code position (16-position sweeps, before the segments and inside pfor's segment), not the clear loop's registers (hand swaps level), not the note (with the note call gone, or preserve_most, it stays); a caller-saved clobber before the call removes half of it.
  • Test gate 1942/1942 here (new test array_field_offset_wrap: three-word elements set and got at indices past 2^32 - 8, in a loop and once; a version whose blk_at does not mask segfaults on it). Merged into opt/integration: 1855/1980, the 125 failures exactly the three shards whose minis have no /usr/local/bun/bin/bun right now (integration alone: 1938/1979, the same cause). Gate note: a shard whose command is about 8,065-8,120 bytes long never starts (the macOS OpenSSH mux client fails with mm_send_fd: sendmsg: Message too long); the test's first comment put two shards there on integration, so 58397c87 shortens it. The 6 lazy_split tests and the new one: 0 live words (-DBEND_POISON) at 1 and 8 threads. comp.ts +143 ttok (92,959 to 93,102).

2026-11-30 (a31ac97b): an idle hunter's spin before it sleeps is timed and adapts (25 µs to 1 ms per thread), not 4096 empty rounds. Cause of 3587c883's +7.4% on parallel-ml/ocaml-nbody-imm at 10 threads: (1) the leaf loop inlined in vss's fork segment compiles to the same instructions with other registers since the note went out of line, and that runs 9% slower on the M4's E-cores (P-cores alike; 5.5% slower at 1 thread under taskpolicy -b); (2) the longer tails crossed fk_help's 4096-round sleep threshold (25 µs on idle cores, 170 µs with 10 threads yielding): 730-875 1 ms sleeps a run, whose wakes the drain's end waits for. The spin is now timed and adapts like POOL_WAIT's (a hunt whose drain ended within a spin of its sleep doubles it, a longer sleep halves it): 30-45 sleeps a run.

  • Cluster (M4 minis), vs opt/integration 247f5c5, median of 15 x 3 jobs: ocaml-nbody-imm 10 threads 140.2 -> 136.5 ms (0.974; before 3587c883: 131.2), 1/2/4 threads level. subset-sum level (its 1-thread +3.5% since 3587c883 is the same register effect, on the clear loop inlined in pfor's fork segment; not fixed). osprey fib and pascal (bend-par), parallel-ml fib, the BFS family, msort, delaunay, seam-carve, mcss, primes, tree-bitonic, the unbalanced and fork-every-level micros: wall and CPU time level at 1/2/4/10 threads (within 3%). All 244 programs print expected at 1 and 10 threads; 1-thread cycles geomean 0.999 (215), 10-thread wall 1.002 (98); the outliers (fib-par 1 thread, tak and collatz 10 threads) were level on rerun.
  • Not done: calling F32 loops out of line in fork segments ([[clang::noinline]]) brought nbody-imm to 130 ms but cost ocaml-nbody 13% and lu-decomp 6% at 1 thread; for every loop it cost msort 27% (the merge took a branch for its select). A fixed 200 µs spin got nbody-imm the same 3% but cost the BFS ports up to 9% more CPU time; the spin in a _Thread_local cost the fork-every-level micro 7% at 2 and 4 threads.
  • Test gate 1974/1974; the 6 lazy_split tests 0 live words (-DBEND_POISON) at 1 and 8 threads; new test lazy_split_leafloop (an F32 loop inlined in a lazily forking segment). comp.ts +307 ttok (92,652 to 92,959).

2026-11-30 (3587c883): forks note only shallow frames or while threads hunt; a noted frame returns through a d segment. The par-split merge made osprey fib bend-par 7.8% slower than main at 10 threads (it is 19% faster at 1 thread). Not the 20 µs limit or the 4-notes rule (turning either off changes nothing): a note at every two-call fork and its drop in the first continuation cost that port (a fork every ~38 instructions) +48% instructions at 2+ threads, and the drop's test +15% cycles at 1 thread; with notes off it ran 0.85x at 10 threads.

  • A fork now notes its frame only while threads hunt, or when the frame is within 8 levels (by the fork's frame size) of its thread's stack base: stacks are 16 MB-aligned, so the test is a mask of sp, no load. A noted frame's id is the fork's new d segment, which drops the note and jumps to the first continuation; a first call answered in the fork's own segment (an inlined base arm) drops it there (WL_FKARM). The first continuation tests nothing.
  • A split needs the polling fork 16 words above the frame (was 4 notes above). The tests are laid out as unlikely (a taken branch per fork cost fib 30% at 2 threads) and the note itself is out of line (inlined, it cost osprey pascal +5% at 1 thread).
  • Cluster (M4 minis), vs opt/integration: osprey fib bend-par 0.86x at 1, 0.91x at 2, 0.89x at 4, 0.87x at 10 threads (8.03 ms; main 8.45); the fork-every-level micro 0.84x/0.92x/0.83x/0.85x; unbalanced micro, bfs, msort, parallel-ml fib, pascal, tak, coins level; tree-bitonic 0.97x. All 244 programs print expected at 1 and 10 threads; 1-thread cycles geomean 0.997 (215), 10-thread wall 0.999 (98). Loss: parallel-ml/ocaml-nbody-imm +7.4% at 10 threads (130 -> 140 ms, at every one of 16 code positions; still +5% with lazy forks off at run time, so it is clang's code for the vss/energy fork segments, plus hunters crossing fk_help's sleep threshold). Test gate 1971/1971; 188 tests 0 live words (-DBEND_POISON) at 1 and 8 threads; new test lazy_split_arms. comp.ts +892 ttok (91,760 to 92,652).

Stacked on #33, which is stacked on opt/integration (1bae016): this PR's own commit is 6938a7d6. comp.ts +3,465 ttok over #33 (87,877 to 91,342). Measured on one Mac (M4, 4 P + 6 E cores), GPU off, under the shared lock; other processes held at most 2.0 cores during the A/B below. The cluster gates have not been run.

What

A drain runs each of its tasks in sequence on the thread that claimed it, and a task never moves. When one task holds most of a drain's work (one corner of an unbalanced fork tree), it runs on one thread while the others wait for the next turn. This is lazy task creation for the drain:

  • A two-call fork run in sequence notes its first call's frame on the thread's fork list (only threads of a pool with more than one; the test is a bit of seq, a register, so one thread pays a test and a branch per fork and its first continuation).
  • Threads past their claims hunt. While more hunt than tasks wait, a note turns the thread's oldest unsplit frame into a task, at most once per 20 µs of a thread: the fork's s segment reads the second call's arguments off that frame (as its first continuation would) into a task whose answer goes to a future, in a slot of the thread's box, and writes the fork's w segment into the frame's id word.
  • Returning there, w takes the task back and runs it, or waits for the thread that took it, running others' tasks meanwhile; then it continues as the first continuation would.
  • A drain still ends when its claims do: a claim waits for every task split off it. A hunter that finds nothing for a while sleeps until a task is boxed or the drain ends.

Without the 20 µs limit, bend-runtime/tree-bitonic split 3.3 million small frames at 10 threads and took 2,682 ms against 1,292; with it, 1,315.

Effect

Wall ms, median of 5, #33 and this PR interleaved:

program 1 thr #33 1 thr this PR 10 thr #33 10 thr this PR
unbalanced fork tree (micro, item i holds 1/(i+1)) 2979 2983 1031 358 0.35x
bfs 957 953 307 298 0.97
delaunay 2972 2961 854 830 0.97
msort 1188 1186 202 198 0.98
bfs-tree-entangled-fixed 945 903 427 426 1.00
mcss / nearest-nbrs / triangle-count / primes / 1000 rounds of 64 leaves 0.99 to 1.00
seam-carve 965 966 284 297 1.05
one array forked per element (micro) 74 85 1242 1323 1.07
fib with a fork at every level (micro) 42 54 8 12 1.39

The unbalanced micro now scales 8.3x on 10 threads (2.9x before). The parallel-ml programs these were found in (primes, primes-simple-bool) do not gain: they run the same instructions at 10 threads as at 1 but 2.7x the user time, memory traffic (lanes of different primes unmark the same lines of a 400 MB array), not the scheduler.

Cost. Fine-grained forks pay the note and its drop: the fib micro (a fork every ~38 instructions) +31% at one thread (+4.7% instructions; the rest is the drop test in the first continuation, measured by removing it by hand), +39% at 10. Over the 244 bend-benchmarks programs at one thread, instructions against #33: geomean 1.0016 over the 215 outside the set apart (the harness-hoisted 28, rbtree-ck), within this machine's run-to-run noise of up to 2.7%; above it: osprey/fib (bend-par) +6.5%, polybench/atax +5.1%, osprey/pascal (bend-par) +4.3%, polybench/bicg +3.9%. At 10 threads, wall geomean 0.980 over 157 programs above 0.1 s (one run each).

Checks

  • All 244 programs print expected.txt at 1 and 10 threads.
  • Native lane, 1,100 tests: no status differs from integration (952 pass, 25 FAIL, 123 that do not emit).
  • Memory check (-DBEND_POISON, live words) at 1 and 8 threads on the 117 tests that fork and the new tests: 0 live words but io/heap_large_reuse (65,536, as on integration).
  • Metal: the 53 ! tests built with bend -o, run with --gpu on, print the same as on integration; the notes are empty on the device.
  • New tests in tests/run/: lazy_split_deep (a fork chain 20,000 frames deep beside a filler tree, both sides), lazy_split_unbal (item 0 holds half the work), lazy_split_results (second calls returning a tree, a list and a pair), lazy_split_shared (one array forked to every leaf). Right at 1, 2, 4 and 10 threads, 3 runs each.
  • Wrong versions: splitting the newest frame (whose frame is not written yet), not waiting for a split task, reading the wrong answer word, a steal without its compare-and-swap: each gives wrong answers in the new tests. Not dropping notes exhausts memory (killed by the 4 GB cap). Never taking a task back, no 20 µs limit, and hunters that never hunt only change the speed.

🤖 Generated with Claude Code

@nicolas-abril

Copy link
Copy Markdown
Owner Author

Pushed 6274bc80 (+127 ttok) and 60f7605e (tests), and merged #33's 3e45065f.

  • tree-bitonic PAR-CPU was 1.31x on the perf gate. The gate runs 16 threads on the 10-core minis. Threads past their claims spun and yielded on cores the remaining claims needed: 980k sched_yield and 3.6 s of sys time. They also split 260k small frames, and 177k of those were stolen and waited on. A thread now hunts only while busy threads plus hunters are fewer than the cores (fk_busy). fk_poll splits only a frame with FK_DEEP = 4 notes above it.
  • tree-bitonic, wall s, median of 5, as before this PR / this PR / now: 16 threads 1.157 / 1.632 / 1.250; 10 threads 1.187 / 1.257 / 1.239.
  • The unbalanced micro keeps its gain: 16 threads 1.012 / 0.855 / 0.850.
  • nbody RSS at 16 threads: 2.36 / 3.18 / 2.97 MB. About 0.2 MB of what's left is one 16 KB page of fork list per thread.
  • Still open: the per-fork note costs tree-bitonic about 11% by itself, measured with hunting off and notes on against notes compiled out. At 4 threads it is 1.72 s against 1.99 s. Only a note-free design, where the poll walks the owner's stack, would remove it.
  • Tests: the four lazy_split tests had a main of type U32, so the interpreter lane printed them from the checker's normal form. Each took over 100 s there, past the gate's cap. They now print run(), the old main, through IO.print. C at 1/2/4/10/16 threads, JS and the interpreter all print the same.
  • Checks: the 51 forking tests print right with 0 live words (-DBEND_POISON) at 1, 8 and 16 threads.

nicolas-abril and others added 16 commits December 1, 2026 22:00
… open

A drain runs each task in sequence, so a task that holds most of a drain's
work (one corner of an unbalanced fork tree) runs on one thread while the
others wait for the next turn. Now a two-call fork run in sequence notes its
first frame on the thread's fork list (a seq bit, so a thread without one
tests a register). While threads that ran out of claims hunt and fewer tasks
wait than hunt, a note turns the thread's oldest unsplit frame into a task:
the fork's s segment reads the second call's arguments off that frame, as
the first continuation would, into a task whose answer goes to a future in
a slot of the thread's box, and puts the fork's w segment in the frame's id
word. Returning there, w takes the task back and runs it, or waits for the
thread that took it, running others' tasks meanwhile. The oldest frame holds
the largest part left. A drain still ends when its claims do: a claim waits
for every task split off it. An idle hunter sleeps after a while, woken by
a boxed task or the drain's end.

The micro benchmark with an unbalanced fork tree (item i of 1024 holds a
share 1/(i + 1)) goes from 1053 to 385 ms at 10 threads (2.86x to 7.81x of
its 3010 ms on one thread).

Tests: tests/run/lazy_split_{deep,unbal,results,shared}.bend.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 6938a7d)
…rame with 4 notes above it

At 16 threads on 10 cores (the perf gate's PAR-CPU), tree-bitonic took
1.63 s against 1.16 before lazy forks: past-claim threads spun and yielded
(980k sched_yield, 3.6 s sys) on cores the remaining claims needed, and
split 260k frames near the top of their stacks, 177k of them stolen and
waited on. A thread past its claims now hunts only while busy threads and
hunters are fewer than the cores (fk_busy), and fk_poll splits the oldest
frame only with FK_DEEP = 4 notes above it.

tree-bitonic, wall s median of 5 (before lazy forks / this PR / now):
16 thr 1.157 / 1.632 / 1.250; 10 thr 1.187 / 1.257 / 1.239.
The unbalanced micro keeps its gain: 16 thr 1.012 / 0.855 / 0.850,
10 thr 1.028 / 0.851 / 0.859. nbody RSS at 16 thr 2.36 / 3.18 / 2.97 MB.
The lazy_split tests and fork_exit_turns print right at 1, 2, 4, 10 and
16 threads (3 runs each); the 51 forking tests print right with 0 live
words (-DBEND_POISON) at 1, 8 and 16 threads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 6274bc8)
…lane does not normalize them

A main of type U32 is printed from the checker's normal form: each of the
four took over 100 s there (past the gate's 30 s, some past its 4 GB).
main now prints run() (the old main) through IO.print: the interpreter
answers in under a second, and C (1, 2, 4, 10 and 16 threads, 3 runs) and
JS print the same as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 60f7605)
…a noted frame returns through a d segment

A note at every two-call fork (and its drop in the first continuation)
cost osprey fib's bend-par port (a fork every ~38 instructions) +48%
instructions at 2+ threads and the first continuation's test +15% cycles
at 1 thread; at 10 threads it ran 7.8% slower than main.

A fork now notes its frame only while threads hunt or when the frame is
within FK_LEVELS = 8 levels (by the fork's frame size) of its thread's
stack base; stacks are 16 MB-aligned, so the test is a mask of sp. A
noted frame's id word is the fork's new d segment, which drops the note
and jumps to the first continuation; a first call answered in the fork's
segment (an inlined base arm) drops it there (WL_FKARM), so the first
continuation tests nothing. A split needs the polling fork 16 words above
the frame (FK_DEEP, was 4 notes). The tests are laid out as unlikely and
the note itself is out of line (fk_noted).

New test lazy_split_arms: forks whose first call is answered in place
(own and another def's tree), right at 1, 2, 4 and 10 threads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 3587c88)
… not 4096 empty rounds

fk_help put a hunter to sleep after 4096 empty rounds. Those took 25 us
on idle cores and 170 us with 10 threads yielding, so whether a hunter
slept turned on how many others yielded, and a sleeper costs the drain's
end its wake. On ocaml-nbody-imm at 10 threads, 3587c88's slower E-core
leaf (below) put the drain tails right at that length: 730-875 1 ms
sleeps a run (mostly none before it). The spin is now timed (read every
64 rounds) and adapts per thread like POOL_WAIT's: a hunt whose drain
ended within a spin of its sleep doubles it (25 us up to 1 ms), a longer
sleep halves it. nbody-imm now sleeps 30-45 times a run, 140.2 -> 136.5
ms. A fixed 200 us got nbody-imm the same but cost the BFS ports up to
9% more CPU time; kept in a _Thread_local, the spin cost the fork-every-
level micro 7% at 2 and 4 threads (it lives in the thread's alc row).

The rest of nbody-imm's loss is clang's, not the scheduler's: the leaf
loop inlined in vss's fork segment compiles to the same instructions
with other registers since the note went out of line, and that runs 9%
slower on the M4's E-cores (P-cores alike: 5.5% slower at 1 thread
under taskpolicy -b, equal at full speed). Calling F32 loops out of line
in fork segments fixed it but cost ocaml-nbody 13% and lu-decomp 6% at
1 thread (and msort 27% for all loops), so it is not done.

New test lazy_split_leafloop: an F32 loop inlined in a lazily forking
segment, right at 1, 2, 4 and 10 threads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit a31ac97)
…et folds into the load

ocaml-nbody-imm's leaf loop (inlined in vss's fork segment) built each
field's u32 index with a mov and a bfi. Since 3587c88 clang put those in
odd registers, and the M4's E-cores run fewer register writes per cycle when
most go to registers of one parity: 9% slower per leaf on E-cores, P-cores
alike. An index is below 2^31 (5-bit class), so index + offset never wraps
in a u64 and the loads take the offset as an immediate. The device keeps
u32. New test array_field_offset_wrap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 3108eef)
Its length moved two of the gate's shard scripts on opt/integration into a
window (about 8,065 to 8,120 bytes of command) where OpenSSH's mux client on
macOS fails to pass the session's fds (sendmsg: Message too long).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 58397c8)
…it whole

The 8-leaf psum ports (Osprey bend-par) grow on 2 rows; each grow thread
ran a whole leaf (a long spin) before its deadline while 8 threads waited,
then the drain ran the other 6 leaves: at most 6 of 10 threads busy. Where a
def that forks lazily calls an outer spin whose step runs a loop, and only
matches and arithmetic on the segment's words precede the call, the segment
in a grow (seq == 0) returns a task that reruns it in sequence (fk_defer),
up to 4 a thread per turn, and only in turns with fewer rows than threads.
The drain deals those tasks like any other. The spin and the code in
sequence are unchanged, so nothing changes at one thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit d3fbe48)
leaf_defer asked, for every spin, whether each line of every segment
contains its name and "(": a string built per spin and line, and a scan of
all the program's lines per spin (twice for inner, once per spin it was
asked for). On app_slash_boss_3d that was 0.4-0.56 s and 500 MB of garbage,
the emit's peak (1.33 GB RSS). Each segment's called names (every name a
call's name ends in, as the substring test reads them) are now collected
once per segment. app_slash_boss_3d's emit: 2.17 s, 1.33 GB -> 1.80 s,
0.78 GB RSS; the emitted C is byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit a9e7b8c)
…eter lane does not normalize them

A main of type Nat is printed from the checker's normal form, and on 16
leaves of 60,000 gcd loops the checkup lane never finished (the cluster
gate requeued those shards without end). As in the lazy_split tests,
main now prints run() (the old main) through IO.print: the checkup
answers all three in 0.2 s, at the same sizes, and the C is the same
apart from main. Without the purity rule, fork_leaf_defer_drop still
crashes at 8 threads under the poison build (6/6); the correct build
leaves 0 live words at 1 and 8 threads on all three.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 5a66f04)
…names it

The leaves were found for every spin before the segments were scanned for
the pattern, and each segment's called spins were read with two regexes
over every line. A spin is now tested when a candidate names it, and a
line with no spin_ or lane_ in it is skipped. Same C on the 244
benchmarks, the tests and the real programs; leaf_defer was 1.4 s of
the 244's emit and 0.48 s of bendquest's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 1782aad)
…a leaf

primes' and mutual's bend-par leaves are go(n, i, 0, isPrime(i)) and
go(n, i, 0, eo(i % 1000, True)): a spin call precedes the leaf call, and the
rerun may not repeat it, so neither port was deferred. The grow now defers
before a run of calls and declarations that leads straight to the leaf. The
rerun in sequence makes those calls once, so they need not be pure: a loop
that frees, reads or writes the segment's values before the leaf is still
exact. What precedes the deferral is held to the old rule (matches and
arithmetic). A segment with no call in that run keeps its deferral where it
was, so only primes and mutual change C among the 244 benchmarks.

Tests: fork_leaf_defer_free (the loop frees the segment's list),
fork_leaf_defer_shared (a list both halves and the caller share),
fork_leaf_defer_write (the loop writes the segment's array in place).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 81e3937)
…rst call

The walk back from the leaf moved the deferral only to the start of a call
block, so declarations above the first call (fork_leaf_defer_write's array
reads, blk_loc / blk_read) stayed before it and failed the purity rule.
Once the run holds a call, the deferral now goes to the run's top; a run
with no call still leaves it at the leaf, so msort's and skyline's merge
segments are byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 3e25d4a)
A run mapped the main thread's 4 GB fork list at start-up when it had
more than one thread, though its first use is in the pool, which opens
only when a fork is dealt. Now the main thread maps it when the pool
opens. Nothing on a hot path changes.

(The fork-list part of opt/lazy-startup's cfcf168.)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant