Step 28: what round 7 found in the runtime
Round 7’s Mo worker left four toolchain bug notes and six gaps (control-run-7). The map write that copies the whole map is the one every program with a growing map pays for; replay is the runtime’s slowest path against Go. This step is the runtime’s, not the language’s: no syntax.
Orientation
../mo-lang-control7-mo/examples/programs/jobq/TOOLCHAIN-BUGS.md and programs/logstat/TOOLCHAIN-BUGS.md (the four reproductions), that worktree’s examples/GAPS.md (the six gaps; evidence, read only, change nothing there), toolchain/src/vm.zig and runtime/mo_rt.c (values, maps, regions), bytecode.zig and emit_c.zig (the at-rest rule from step 27, part C), 09-stdlib.md and PRELUDE.md (the Fs, Option, integer, and Clock rows), sim.zig (the fixture clock), bench/ (the kv and reuse-map-* rows).
Write scope
toolchain/, examples/, and the spec rows the parts name in 09-stdlib.md and PRELUDE.md. Branch session-05, one commit per part, Step 28 part X in the subject, push after every commit, zig build test green at every commit.
Part A: a map written in place
Setting an existing key or removing one copies the whole map in both runtimes (2,000 writes at 80k entries: 22.7 s inside an update). A map held by exactly one owner (a var, a state field, an accumulator) is written in place; a map with another holder is copied once and then written in place. The same for a list’s set and a struct’s field write where the struct is uniquely held, if they copy today. A bench row map-set-80k (2,000 overwrites at 80k entries) and map-remove-80k before and after, both runtimes; the reuse-map-* rows kept.
Part B: a reduce with a tuple accumulator, and the never rule’s gap
- A
reducewhose accumulator is a tuple copies it each step (1,214 ms against 19 ms for a plain accumulator): the accumulator is moved, not copied, in both runtimes. A bench row. - The at-rest rule (step 27, part C) still records a
varcopy when the second write sits inside anif: the rule looks past a branch to the body’s next write of the same root name, so avarwritten in two arms and then again after theifis recorded once, at its last write.contracts/never-var-copy.mogains the logstat shape (+= 1thenif error: next.errors += 1 end).
Part C: resident memory and replay
- Resident memory grows far past what the regions hold (120 MiB held at 40k jobs against 12 MiB in the regions) and
MemoryInfodoes not see the difference: find where it goes (freed regions not returned, the allocator’s retention, mailbox or connection buffers, the C runtime’s arenas), fix what is fixable, and makeMemoryInforeport resident and region bytes both. Numbers at 100k jobs, both runtimes, before and after. - Replay of a 1M-record log is 15.3 s native against Go’s 4.8 and Python’s 5.2: profile the store recipe’s replay path (
read_linesorfold_lines, JSON decode, the map writes from part A) and take what part A gives; report the split. A bench rowreplay-1mbefore and after.
Part D: the six gaps
Fs.listtells a file from a folder: anEntrywithnameandkind, or aFs.list_kindsrow, whichever is plainer, with09-stdlib.mdandPRELUDE.mdrows.- A thousands separator:
n.to_s(grouped: true)orString.grouped(n), writing1_204. - An anonymous function may leave a parameter unread by naming it
_. secondson an integer (10.seconds), besidems,minute, anddays; and a wrong unit (1.second) is a check-time diagnostic naming the units, not a run-time crash.Option.map.- A fixture clock that follows the simulator’s time:
Clock.fixture()moves when a fixture wait or a delayed send moves the simulator, so a process test can watch a lease run out;03-semantics.mdor09-stdlib.mdsays so in one sentence, the worker names which.
Each with a corpus file or an extension of one, under mo test, --sim 100, and as a test binary.
Part E: both runtimes and the corpus
The whole suite green; mo fmt --check clean; every new row in both runtimes; the bench rows recorded.
Numbers
map-set-80k, map-remove-80k, the tuple reduce row, replay-1m, resident memory at 100k jobs, kv-10k-get, logstat-4k, before and after, both runtimes.
Done when
Green at every commit; the map in place with its rows; the tuple accumulator moved; the never gap closed with its corpus line; memory accounted for and replay’s split reported; the six gaps with their files; the numbers; pushed; a numbered list “Decisions the brief did not cover”.
Result
Accepted 14 Sep 2026, 23:55 UTC. Five commits (A, B, D, C, E), green at each, 186 of 186 at the end; about 3 h 45 min of worker time including Robert’s pause, during which part A’s suite had hung on a jobq test binary and was fixed before A landed. Part A: src/moves.zig, a move analysis shared by both backends (a local’s last read hands its value on; lists, map keys and values, sets, messages, and captures give the claim up; structs, tuples, variants, and accumulators keep it), remove in place with an undo, the owned and growth rings as tables. Part B: the tuple accumulator fixed by A; the never rule looks through branches; basics/moves.mo and contracts/never-var-copy.mo extended. Part D: the six gaps with their corpus files and rows. Part C: regions give pages back past their top; MemoryInfo.region_resident_bytes; a leak of part A’s own found and fixed; the remainder outside the regions is Zig’s allocator retaining packed message buffers, measured and left. Part E: the bench recorded.
Numbers (the worker’s, before → after): map-set-80k 47,071 → 128 ms interpreted, 21,323 → 5 ms native; map-remove-80k 37,906 → 760 and 8,232 → 167; reduce-tuple-50k 4,453 → 37 and 999 → 9; replay-1m 281 → 196 s interpreted, 63.9 → 43.1 native (split: compaction 50%, map sets 22%, string slicing 20%); memory after that replay 392 → 102 MiB and 183 → 57; kv-10k-get and logstat-4k within noise; two rows slower (reuse-map-remove-100k interpreted 76 → 97 ms, http-1k interpreted 37 → 51 ms). Fable’s measurement of round 7’s Mo jobq rebuilt on this toolchain with the round’s one client: creates 1,266 a second (1,320 before), pairs 293 / 944 at 1 / 32 workers (329 / 981), 159 MiB at 100k jobs (150), restart 3.3 s (3.7) and 57 MiB after it (181); the defect suite 121 of 121.
Fable’s probes: 80k entries and 2,000 overwrites plus 2,000 removes inside an update in 0.09 s interpreted and 0.03 s native, 400k and 20,000 in 0.41 s, the values read back; a tuple accumulator over 100k items in 0.05 s; the logstat Tally shape passing under mo test and as a binary; 1.second refused at check time naming the units; list_kinds, grouped, _, Option.map from mo run and a binary. Left: the ~100 MiB Zig’s allocator retains; replay still nine times Go’s on the same log.