# Runtime (/docs/experiments/runtime)

This page records the runtime experiments of 2026-11-14 to 2026-11-17: what was tried, why, how it was measured, the result, and the decision. Dropped experiments are included. Revisions are commits of the compiler repository. Linux numbers come from the linux/amd64 benchmark machine (16 cores). Unless a section says otherwise, timing runs went through the shared job queue, one at a time.

Terms:

- perfcmp: the A/B tool (tests/perfcmp). It builds the benchmark set (hello, ten bench programs, sketch, tuios) with two toolchains or two environments. It compares wall time, CPU time, RSS and size in dev, O2 and release mode. Its verdict passes only with exit 0. It refuses to judge when the machine load is high (INCONCLUSIVE).
- Stop: a stop-the-world pause of the garbage collector.

## Summary (night of 2026-11-16 to 2026-11-17) [#summary-night-of-2026-11-16-to-2026-11-17]

Landed on main:

- Concurrent marking refuses binaries without a write barrier (cb7152e5, section 1).
- A map gives its old table back when it rebuilds. Large freed objects return their pages at once (9917e9bc, section 12): peak RSS mapint 144 to 107 MB, mapstr 138 to 111 MB.
- The collector's register buffer is zeroed, so stale stack words no longer keep dead objects alive (961b5f85, section 13).
- Wasm tracebacks through host imports (96394991) and JSPI goroutine switching, opt in, with an engine stack pool (bb7c965f) on 2026-11-16.

Held for its own gate (section 17): collect before a large allocation that crosses the trigger. It cuts peak RSS a lot: wordfreq 550 to 409 MB (go 401), stringsearch 28 to 17 MB, nsieve 85 to 31 MB, regexpbench 82 to 65 MB. But in its first form it doubled or tripled the collection count of some programs. It also slowed mapstr by 4 to 8% CPU. A guarded version is being measured.

Found and handed over: jsondec's 2x RSS is dead locals in main's frame (precise stack liveness, section 14). sortslice's 1.7x RSS is the allocation volume of fmt.Sprint argument boxing (section 18). The 1.5x RSS of small programs is a 2 MiB transparent huge page on the first heap touch. Section 19 has a candidate fix with a CPU cost to measure.

Dropped, with the reason: tighter page release policies (section 15). They cost CPU and did not lower the peak once a zeroing bug was understood. Also MADV_NOHUGEPAGE for the runtime's sparse tables (section 16), and the scheduler CPU work (section 11, no gap left).

## 1. Concurrent marking refuses binaries without a write barrier [#1-concurrent-marking-refuses-binaries-without-a-write-barrier]

- What: MARMOT_GC_CONC=1 marks the heap beside the running program. That is only safe when the compiled code has a write barrier (MARMOT_WB=1 or card marking). The runtime had no way to know. Now the module of package main defines a constant rt_wb_kind (0 none, 1 flag barrier, 2 cards). The runtime holds a weak 0. When MARMOT_GC_CONC=1 is set and rt_wb_kind is 0, the runtime prints a warning and uses stop-the-world collection.
- Why: a dev build of a large terminal program died mid-flood with MARMOT_GC_CONC=1 and no barrier. The collector freed live objects. Its stop-time numbers from that run were invalid.
- Measurement: runtime tests gc_conc_nowb (the warning, then a stop-the-world collection keeps a 10k-element list intact), gc_conc, gc_card and gc_sigstop (they define the symbol). perfcmp of the runtime change against main: run 1 hit the build time limit at load 14, and run 2 was INCONCLUSIVE at load 12.3. Run 3 passed: dev geomean 0.993, release 0.998, noise 1.012 and 1.015, exit 0.
- Verdict: landed (cb7152e5, codegen half 4c9190a6).

## 2. GC stop times with precise globals (MARMOT_NOPTR, MARMOT_GCVARS) [#2-gc-stop-times-with-precise-globals-marmot_noptr-marmot_gcvars]

- What: the stop times of a dev build of a large terminal program with card marking, during two 50 MB output floods. Three builds: base, MARMOT_NOPTR=1 (data without pointers in its own section, not scanned), and MARMOT_NOPTR=1 MARMOT_GCVARS=1 (precise records for pointer globals).
- Why: a trace showed that a stop of about 4.5 ms spent 4.2 ms in the conservative scan of 45 MB of data and bss. Precise globals remove most of that scan. Runtime support landed before this. The collector skips noptr sections and untouched data pages (6f4e3e3e) and scans records precisely (90710607). Threads that miss the stop signal get a retry (6de92b10).
- Measurement: 7 collections per flood, two floods per variant.

| Variant | First stop p50 | First stop p99 | Idle CPU in 60 s |
| --- | --- | --- | --- |
| base | 1.47 to 1.53 ms | 1.84 to 1.93 ms | 0 |
| NOPTR | 1.17 to 1.28 ms | 1.78 ms | 0 |
| NOPTR and GCVARS | 1.17 to 1.38 ms | 1.44 to 1.66 ms | 0 |

- RSS (5 runs each, medians 76.9, 76.6 and 76.4 MB): the differences are noise.
- Verdict: NOPTR cuts the first stop by about 20%, with no memory cost. The flag belongs to the front end, which gates its default flip.
- Next: the default flip (front end), then a dirty-page design for the remaining scan (section 12).

## 3. Startup memory of a large program: init code, PIE, RELR [#3-startup-memory-of-a-large-program-init-code-pie-relr]

- What: measured the RSS of tuios --version (92 MB executable) in dev mode. Variants: base (PIE), MARMOT_INITSECT=1 (package init code grouped in .text.startup), INITSECT with a non-PIE executable, and INITSECT with PIE plus RELR relocations.
- Why: the Linux dev build used about 59 MB at startup against about 32 MB on macOS. The breakdown showed two causes. Init code spread over all of the text (most of the touched text pages), and PIE relocations (.rela.dyn read in full, .data pages dirtied).
- Measurement: 5 runs each, maxrss.

| Variant | maxrss | text RSS | Size |
| --- | --- | --- | --- |
| PIE (base) | 58 to 60 MB | 21.6 to 22.7 MB | 92.9 MB |
| INITSECT | 50 to 52 MB | 14.4 to 14.7 MB | 92.9 MB |
| INITSECT, non-PIE | 38 MB | 14.8 MB | 79.6 MB |
| INITSECT, PIE with RELR | 38 to 41 MB | 14.9 MB | 79.7 MB |

- INITSECT perfcmp: the first run was INCONCLUSIVE (load 15.1, noise 1.024 in dev). Release geomean 0.988 (tuios 4% faster, RSS 0.909). The dev rows that looked worse (matmul 1.146, spectralnorm 1.119, iface 1.08) each had one slow run. INITSECT does not change those loops, so these were load. A rerun in dev, O2 and release is queued.
- Verdict: INITSECT saves 8 MB (14%). RELR or non-PIE saves another 12 to 13 MB. Total: about 59 to 38 MB, 0.65x of the base. The flags belong to the front end and tier 0.
- Next: flip INITSECT on exit 0. Then gate INITSECT plus RELR against INITSECT. Gate non-PIE only if RELR loses.

## 4. Wasm: wrong pointer bitmaps on 32-bit targets (found and fixed) [#4-wasm-wrong-pointer-bitmaps-on-32-bit-targets-found-and-fixed]

- What: 100,000 goroutines that each add their index under a mutex gave a wrong, changing sum on wasm. Native was right, and 10,000 goroutines were right on wasm.
- Cause: the type descriptors were built with 8-byte words on wasm32, where a pointer is 4 bytes. A pointer at an offset of 4 mod 8 had no bit, so the collector did not scan it. A closure context struct\{F unsafe.Pointer. X0 *int\} had gcdata 0x01 and the captured variable was freed. The runtime was right.
- How it was found: the sum was right with GOGC=off and wrong as soon as one collection ran. MARMOT_STACKSIZE from 64 KiB to 256 KiB changed nothing, which ruled out stack overflow. 5000 closures kept in a slice across runtime.GC() gave 3996 wrong values, without goroutines. A struct with a pointer at offset 0 survived.
- Verdict: fixed in codegen (a3f3d429), tests closure_gc and goroutine_sum (fed86223). After the fix: 0 of 5000 closures wrong, and the 100k sum right with 3 collections. 1000 goroutines with a collection every 50 allocations are right (63 collections).

## 5. Wasm tracebacks through host imports [#5-wasm-tracebacks-through-host-imports]

- What: on wasm there are no frame records in memory, so panics printed no frames and runtime.Caller failed. A host that can see the wasm stack now provides two imports. marmot.callers gives the module offsets of the frames, from the engine's stack trace. marmot.pcln gives the pc table section. The runtime copies the table in on the first lookup. The driver builds the table from the final module through a source map.
- Measurement under node with a reference host (runtime/core/test/wasm/callers.mjs), dev and release. runtime.Caller(0) and Caller(1) give the right file and line. Callers and CallersFrames name every Go frame with its line. A nil map panic prints every frame. Without the host imports nothing changes.
- A finding on the way: the first version moved the native frame walk to a file that sorts before extern.go. That changed the import order of the runtime package, and two package init calls swapped places in every native binary. Renaming the file made the native code byte-identical again. In 36 builds (12 programs, dev, O2, release) only the pc table section differs.
- Verdict: landed (96394991, driver 80ccafba, reference host 11766614).

## 6. JSPI goroutine switching on wasm (opt in) [#6-jspi-goroutine-switching-on-wasm-opt-in]

- What: a second wasm runtime library in which every goroutine runs on an engine stack of its own, through JavaScript Promise Integration. A switch is an import that the host wraps with WebAssembly.Suspending. Pointers live across calls go to the shadow stack through wasm-opt --spill-pointers, so the collector still finds them. The default library keeps Asyncify.
- Why: Asyncify rewrites every function that can reach a switch. That doubles code size, makes a switch cost grow with stack depth, and is the slowest step of a playground build.
- Measurement, small C test and a real Go program (fmt, sort, channels, goroutines), node:

| | Asyncify | JSPI |
| --- | --- | --- |
| Module size, wasm-opt without -O | 1.67 MB | 0.79 MB |
| Module size, -O2 | 0.83 MB | 0.60 MB |
| wasm-opt time, without -O | 0.26 to 0.34 s | 0.10 s |
| wasm-opt time, -O2 | 1.8 s | 0.55 s |
| Switch, stack depth 0 | 195 ns | about 600 ns |
| Switch, stack depth 100 | 1592 ns | about 610 ns |
| Channel ping-pong, real program | 767 ns | 781 ns |

- The engine floor: one suspend and resume through a Suspending import costs 100 to 200 ns, and a yield is two switches.
- Engine stack pool: a new engine stack costs about 10 us. An exited goroutine now leaves its engine stack to the next new goroutine, which a longjmp back to the stack's loop starts. 100k goroutines run one after another: 1231 ms before the pool, 203 ms with it, 224 ms with Asyncify. A churn test made 9100 goroutines on 101 engine stacks.
- Checks: runtime suites on native, default wasm and JSPI (new tests exit_goroutine, fatal_goroutine, goroutine_churn). One set of Go objects linked with both libraries gives the same output with GC on. Native libraries and the default wasm library are byte-identical. The default wasm bitcode differs only in two inline asm source offsets.
- Verdict: landed opt in (bb7c965f). The playground selects JSPI when the browser has it, else Asyncify.
- Next: direct handoff (switch from goroutine to goroutine without the scheduler stack, it halves the engine cost). The driver drops the marmot_gorun export today, so marmot build cannot make a JSPI module yet.

## 7. Many goroutines on wasm [#7-many-goroutines-on-wasm]

- What: 10k and 100k goroutines parked at once, then woken.
- Measurement (node): 10k: spawn and park 36 ms Asyncify, 143 ms JSPI. Wake and exit 6 ms and 137 ms. 100k fail with both at the default 64 KiB stacks: 100k stacks are more than the 4 GiB address space. With MARMOT_STACKSIZE=16384: Asyncify 383 ms and 44 ms. JSPI 7.5 s and 21 s, because the engine's cost per suspended stack grows with their number.
- Verdict: the default stack size stays 64 KiB (deep recursion would trap with less). MARMOT_STACKSIZE is the knob, and the playground sets 16 KiB. JSPI does not scale to 100k parked goroutines in node.
- Next: growable wasm stacks (design note: linked segments with a prologue check, a copy is not safe with a conservative scan).

## 8. Asyncify cost in the playground (analysis, no change) [#8-asyncify-cost-in-the-playground-analysis-no-change]

- Question: the Asyncify step takes 6 to 9 s in the playground and 10 to 21 s in browsers without JSPI. asyncify-ignore-indirect gave no gain. Why?
- Finding: the conservative collector needs every frame's locals in memory. With Asyncify, rt_spill_regs gets them there with an unwind and rewind. The collector and the allocation slow path (through rt_safepoint) call it, so every function that can allocate reaches the unwind through direct calls.
- Experiment (not landed): rt_spill_regs without the unwind, --spill-pointers for the roots, rt_safepoint empty on wasm (one thread).
  - With asyncify-ignore-indirect: instrumented functions 6649 to 753, module 4.0 to 2.3 MB, pass 0.6 to 0.3 s. But the program skipped its goroutine part and exited 0, a silent wrong result. Ignoring indirect calls is not safe for Go: goroutine entry, closures, defers and interface calls are indirect.
  - Without ignore-indirect: worse (5.6 against 4.2 MB), because spill-pointers adds code and indirect calls still reach nearly everything.
  - Indirect calls resolved by signature against the table: 164 of 175 signatures reach the unwind. 3782 of 4452 functions stay instrumented, against 3812 with the default. No gain.
- Verdict: dropped. A prebuilt Asyncify standard library is not possible: Asyncify works on the linked module only.
- Next: the only sound cut is to resolve indirect calls with Go type information in the compiler (as a VTA call graph). The result goes to Asyncify as a remove list, together with the runtime change above. Upper bound: about 700 instrumented functions. Earlier, a hand-made remove list gained under 10% and was dropped.

## 9. A slow gcstress test (card_fresh_move) [#9-a-slow-gcstress-test-card_fresh_move]

- What: card_fresh_move under gcstress (a collection at every slow-path allocation) hit the 3000 s limit. The question was whether it hangs or is slow.
- Measurement: at interval 1 the collection count rose steadily. There were 63.7k collections in 300 s, 2 to 3 ms each, with RSS flat at 23 to 27 MB. The run needs about 8.6M collections. At interval 1000: pass in 290 s (8651 collections). At 100: over 900 s.
- Verdict: slow, not a hang. The test collects at every 1000th allocation under gcstress (77f9a2c3).

## 10. Dirty-page tracking for the global scan (research, open) [#10-dirty-page-tracking-for-the-global-scan-research-open]

- What: options to avoid scanning unchanged data pages at each stop: soft-dirty bits, userfaultfd write protection, and mprotect with a fault handler.
- Measurement: a micro benchmark and a soft-dirty trace of a large program. The precise-globals work (section 2) removed most of the scan first.
- Verdict: open. The default must work on both Linux and macOS. A userfaultfd prototype behind a flag comes after the new stop numbers.

## 11. Scheduler CPU in channel programs [#11-scheduler-cpu-in-channel-programs]

- What: the last scoreboard (2026-11-12) showed pingpong, selectpipe and workerpool at 0.44 to 0.66x of go's CPU.
- Measurement (2026-11-17, release, perf stat task-clock): pingpong 501 ms against go 988 ms, selectpipe 923 against 1992 ms, workerpool 3653 against 3224 ms. A run-next steal delay (as gc's) landed after the scoreboard date.
- Verdict: no scheduler gap left in pingpong and selectpipe (about 2x less CPU than go). Workerpool is bound by its compute loop, not by the scheduler.

## 12. A map gives its old table back when it rebuilds [#12-a-map-gives-its-old-table-back-when-it-rebuilds]

- What: a marmot map is one table that doubles when full. A rebuild now frees the old table at once, with two conditions. No iteration of the map ever started, because an iterator may still read an old table. No concurrent mark runs, because a marker may already hold the old table. The iteration counter no longer wraps to 0. A freed object of 1 MiB or more gives its pages back to the OS at once.
- Why: every earlier table stayed resident. The next table is twice as large and cannot reuse their pages, and nothing released them before the end of the program.
- Measurement, peak RSS, release, best of 3:

| Program | Before | After | go |
| --- | --- | --- | --- |
| mapint | 144 MB | 107 MB | 95 to 100 MB |
| mapstr | 138 MB | 111 MB | 98 MB |
| others (wordfreq, jsondec, stringsearch, parse, bintrees) | | unchanged | |

- CPU unchanged within noise. Mapint runs 3 collections instead of 6: the freed bytes leave the live count.
- Checks: test map_grow_free. It covers a map that is never iterated, inserts during an iteration that rebuild the table, and a clone of a growing map. It also covers pointer values across collections, and a large value copied out before a rebuild. Same output as go in dev and release, with gcstress, poison, and card marking with concurrent marking and heap verification. A soundness review found one blocker: a free during a concurrent mark. It is fixed. The free is skipped during a mark, and no stop can come between the test and the free.
- Known change: a reader that races a writer (undefined behavior in Go) may now read reused memory instead of a stale table.
- Verdict: landed (9917e9bc). Gated together with sections 13 and 17: perfcmp against main exit 0 (geomean wall/CPU/RSS dev 1.006/1.005/0.986, O2 1.003/1.007/0.986, release 1.007/1.008/0.985). Conformance of the map, GC and allocation tests in dev, release, gcstress and cards 483/484 with and without the changes.

## 13. Stale words in the collector's register buffer [#13-stale-words-in-the-collectors-register-buffer]

- What: the collector and the safepoint stop hand a 24-word buffer to rt_spill_regs. It stores the callee-saved registers (6 words on x86-64, 20 on arm64). The scan of the collecting goroutine covered the whole buffer, and the other words were stale stack memory from deeper calls. The buffer is now zeroed first.
- Measurement: JSON decoding in a function that has returned, then runtime.GC(): 148,849 objects (17 MB) stayed reachable. With the zeroed buffer 719 objects, as go (713).
- Verdict: landed (961b5f85), in the same gate as section 12.

## 14. Dead locals keep large graphs alive (jsondec) [#14-dead-locals-keep-large-graphs-alive-jsondec]

- What: jsondec's peak RSS is 2.16x of go (68 against 31 MB). After a forced collection go keeps 713 objects, marmot 272,851.
- Cause: main's frame still holds the slice of 20,000 structs that is used only before the decode loop. The conservative stack scan cannot know that it is dead. Moving the setup into its own function: 42 MB.
- Tried: MARMOT_GCPTR=1 (stack maps): the release build fails to compile, and at -O 2 the same objects stay.
- Verdict: a compiler task (precise liveness of pointer locals, or clearing dead pointer slots before calls that can collect). Expected: jsondec about 68 to 36 MB.

## 15. Page release policies (dropped) [#15-page-release-policies-dropped]

- What: two variants of go's scavenger policy. (a) After each sweep, keep free pages only up to the room left under the goal plus 10%, instead of the whole goal. (b) Before the heap grows, release free pages so that the backed heap stays near the goal plus 10%.
- Measurement: (a) wordfreq peak 547 to 678 MB, parse CPU +50%, stringsearch 36 to 32 MB. (b) wordfreq 549 to 677 MB, parse CPU 1.4 to 2.1 s.
- Cause found: RSS sampled every 20 ms showed a jump of 180 MB in one sample in the variant. A released span was marked as needing zeroing, although MADV_DONTNEED on Linux already makes its pages read as zero. A merged free span needs zeroing if any part does. A large allocation from such a span ran a memset over all its pages and backed them at once. Released spans are now marked clean, and a release clears large dirty objects instead of a memset. With that, variant (b) no longer raises the peak (550 MB), but it does not lower it either. Parse used about 30% more CPU, because pages faulted in again after a release.
- Verdict: dropped. The peak of wordfreq came from the collection timing, not from the release policy (section 17).

## 16. Huge pages for the runtime's sparse tables (dropped) [#16-huge-pages-for-the-runtimes-sparse-tables-dropped]

- What: MADV_NOHUGEPAGE for the page map, the heap bitmap and the card table, which are large sparse reservations. The machine uses transparent huge pages for every mapping.
- Measurement: no change beyond the run-to-run variation in small programs (2.1 to 4.3 MB for the same binary) or in large ones.
- Verdict: dropped. Most of the remaining small-program gap against go is libc and the dynamic loader (about 1.5 MB of file pages), which a static link removes.

## 17. Collect before a large allocation that crosses the trigger [#17-collect-before-a-large-allocation-that-crosses-the-trigger]

- What: when a large allocation (over 32 KiB) would take the heap past the collection trigger, the runtime collects first and allocates after. Before, it allocated first and collected after, so the collection counted the new object as live.
- Why: a buffer that doubles (bytes.Buffer, append) allocates its new array while the old one is still in use. Collected after the allocation, both arrays counted as live, and the next goal (twice the live heap) included the new array. In wordfreq the heap grew to 659 MB before the next collection.
- Measurement, peak RSS, release, best of 3:

| Program | Before | After | go |
| --- | --- | --- | --- |
| wordfreq | 550 MB | 409 MB | 401 MB |
| stringsearch | 27.7 MB | 17.3 MB | 22.9 MB |
| jsondec | 68.5 MB | 63.5 MB | 31.6 MB |
| mapint, mapstr, parse, bintrees, strconcat | | unchanged | |

- CPU unchanged within noise. Wordfreq runs 18 collections instead of 9. Outputs identical. Runtime suite 81/81.
- Gate (together with sections 12 and 13): perfcmp exit 0, but mapstr was slower in all three modes (wall 1.03 to 1.04, CPU 1.04 to 1.08) for 17% less RSS. Collection counts show why: mapstr 4 collections before, 3 with sections 12 and 13 only, 6 with this change. Each scans about 100 MB. The change also raised counts elsewhere: wordfreq 9 to 18 (go 9), stringsearch 20 to 66 (go 30). This is a risk of back-to-back collections when large allocations keep landing inside the growth room.
- Verdict: held. The next version collects early only on two conditions. The object itself would take the heap past the goal. At least half its size was allocated since the last collection. Measured with collection counts, then gated on its own.
- Follow-up (2026-11-18): DROPPED, a negative result. Three variants were measured (guard past the goal, guard past the goal plus half the size allocated, and the next goal counting the pending object). The last one returns the collection counts to main, and the RSS with them. The gain came only from extra collections, which the 2% CPU rule does not allow. The wordfreq gap was a compiler issue. append([]byte(nil), make([]byte, c)...) in bytes.growSlice allocates two full arrays without MARMOT_APPENDMAKE. With it, RSS goes from 547 to 410 MB (go 401 MB). Stringsearch is at go parity without the change. Details: [Design: early collection](/docs/experiments/runtime/design-earlygc). The guard patch is kept outside the repository history.

## Summary of the peak RSS changes tonight [#summary-of-the-peak-rss-changes-tonight]

| Program | Before | After | go | After / go |
| --- | --- | --- | --- | --- |
| wordfreq | 550 MB | 409 MB | 401 MB | 1.02x |
| mapint | 144 MB | 107 MB | 95 to 100 MB | 1.1x |
| mapstr | 138 MB | 111 MB | 98 MB | 1.13x |
| stringsearch | 35.7 MB (27.7 in later runs) | 17.3 MB | 22.9 MB | 0.76x |
| jsondec | 68.5 MB | 63.5 MB | 31.6 MB | 2.0x (dead locals, section 14) |

## 18. All bench programs, before and after sections 12, 13 and 17 [#18-all-bench-programs-before-and-after-sections-12-13-and-17]

Release builds, one run of each measurement step on a loaded machine (load 5 to 8). Peak RSS is in MB (best of 3), and CPU in ms (perf stat task-clock, best of 3). Indicative only: the gate numbers come from perfcmp. "after/go" is the RSS goal column (target at most 0.7).

| Program | RSS before | RSS after | RSS go | after/go | CPU before ms | CPU after ms | CPU go ms |
| --- | --- | --- | --- | --- | --- | --- | --- |
| bintrees | 39.9 | 40.0 | 45.8 | 0.87 | 3135 | 3128 | 4786 |
| bits | 4.1 | 4.1 | 2.6 | 1.57 | 1016 | 1014 | 13575 |
| bytecount | 4.1 | 4.1 | 4.8 | 0.85 | 19021 | 18479 | 22529 |
| closure | 4.1 | 4.1 | 2.8 | 1.48 | 1094 | 937 | 1623 |
| conv | 4.1 | 4.1 | 4.8 | 0.86 | 1121 | 1111 | 17688 |
| deferloop | 8.5 | 8.5 | 2.8 | 3.09 | 2668 | 2667 | 1073 |
| dot | 4.1 | 4.1 | 2.8 | 1.48 | 8399 | 8730 | 8816 |
| fannkuch | 4.1 | 4.1 | 2.8 | 1.48 | 1769 | 1779 | 1963 |
| fib | 4.1 | 4.1 | 2.8 | 1.49 | 929 | 926 | 1705 |
| fmtbuf | 11.2 | 10.9 | 9.7 | 1.12 | 1612 | 1655 | 1537 |
| fmtlog | 11.2 | 11.2 | 9.8 | 1.14 | 1256 | 1249 | 1149 |
| fmtout | 8.8 | 11.1 | 9.4 | 1.18 | 1387 | 1455 | 1251 |
| generic | 198.6 | 197.6 | 265.1 | 0.75 | 690 | 727 | 731 |
| heapsort | 64.3 | 64.5 | 67.1 | 0.96 | 1431 | 1398 | 1527 |
| hello | 4.1 | 4.1 | 2.8 | 1.49 | 0 | 0 | 0 |
| hellostd | 4.5 | 4.7 | 4.9 | 0.96 | 0 | 0 | 0 |
| histogram | 4.1 | 4.1 | 2.8 | 1.49 | 6900 | 6957 | 8438 |
| iface | 4.1 | 2.1 | 1.2 | 1.71 | 508 | 506 | 725 |
| jsondec | 66.5 | 62.0 | 32.4 | 1.91 | 1120 | 1104 | 1091 |
| jsonenc | 45.2 | 41.0 | 36.5 | 1.12 | 592 | 596 | 516 |
| mandelbrot | 4.1 | 4.1 | 4.8 | 0.86 | 14206 | 14281 | 15383 |
| mapint | 138.7 | 104.4 | 98.0 | 1.07 | 1320 | 1174 | 1322 |
| mapstr | 135.1 | 111.6 | 97.9 | 1.14 | 1130 | 1151 | 1257 |
| mapstruct | 6.7 | 6.8 | 7.0 | 0.97 | 346 | 349 | 490 |
| matmul | 18.4 | 18.5 | 19.4 | 0.96 | 13476 | 12544 | 14717 |
| nbody | 4.1 | 4.1 | 4.8 | 0.86 | 15603 | 15636 | 16198 |
| nsieve | 82.9 | 30.4 | 381.8 | 0.08 | 5310 | 5255 | 9767 |
| parse | 77.4 | 78.1 | 68.6 | 1.14 | 1245 | 1263 | 1261 |
| pingpong | 4.1 | 4.2 | 4.8 | 0.89 | 476 | 489 | 934 |
| prefixsum | 4.1 | 4.1 | 4.8 | 0.86 | 3438 | 3430 | 10542 |
| quicksort | 94.4 | 94.4 | 97.2 | 0.97 | 813 | 796 | 842 |
| regexpbench | 79.9 | 63.6 | 58.0 | 1.10 | 455 | 471 | 553 |
| saxpy | 4.1 | 4.1 | 2.8 | 1.48 | 7229 | 7282 | 13783 |
| selectpipe | 4.2 | 4.1 | 4.7 | 0.87 | 815 | 827 | 1741 |
| sha256 | 8.7 | 9.0 | 5.0 | 1.79 | 54131 | 56197 | 48293 |
| sortslice | 294.7 | 294.7 | 176.6 | 1.67 | 1347 | 1365 | 1401 |
| spectralnorm | 4.1 | 4.1 | 2.8 | 1.50 | 4937 | 4894 | 5814 |
| stencil | 8.4 | 6.4 | 6.9 | 0.93 | 40018 | 6165 | 31553 |
| strconcat | 6.7 | 6.6 | 14.7 | 0.45 | 965 | 947 | 1457 |
| stringsearch | 33.5 | 16.9 | 24.6 | 0.69 | 394 | 371 | 1239 |
| structcopy | 4.1 | 4.1 | 2.8 | 1.49 | 595 | 424 | 2268 |
| summinmax | 4.1 | 4.1 | 1.6 | 2.53 | 7577 | 8011 | 10508 |
| transpose | 68.4 | 66.3 | 67.8 | 0.98 | 5348 | 4511 | 4319 |
| wordfreq | 533.9 | 397.0 | 389.5 | 1.02 | 1438 | 1375 | 1558 |
| workerpool | 2.2 | 2.1 | 1.4 | 1.51 | 3920 | 3982 | 3170 |

Notes:

- Small programs (hello, bits, fib, saxpy and the like) measure 4.2 MB against go's 2.8 MB. Their resident heap is one 2 MiB transparent huge page (section 19).
- nsieve 84.8 to 31.2 MB and regexpbench 81.8 to 65.1 MB were not targeted. Both gain from section 17.
- sortslice: 302 MB against 181 MB, unchanged. marmot allocates 305 MB in 12.0 million allocations, go 171 MB in 7.0 million. That is about 1.25 more allocations per fmt.Sprint call. The likely cause is the boxing of its arguments. go boxes constant strings and small integers without an allocation. The extra garbage takes the heap to its goal. go stays under its goal with one collection. A compiler task.
- jsondec: 2.0x after the changes. The rest is dead locals in main's frame (section 14).
- stencil's CPU difference (40 s before, 6 s after) is a load artifact of that run, not a result.

## 19. No transparent huge pages for the first MiB of the heap (candidate) [#19-no-transparent-huge-pages-for-the-first-mib-of-the-heap-candidate]

- What: MADV_NOHUGEPAGE for the first part of the heap arena. The machine backs every anonymous mapping with transparent huge pages, so a small program's first heap touch backs a whole 2 MiB page.
- Measurement, peak RSS, 5 runs:

| Program | Now | First 8 MiB without huge pages | go |
| --- | --- | --- | --- |
| hello | 4.2 MB | 2.3 MB | 2.8 to 4.9 MB |
| pingpong | 4.3 MB | 2.3 MB | 2.8 to 4.9 MB |
| workerpool | 2.1 to 4.4 MB | 2.1 to 2.3 MB | 4.9 to 7.0 MB |
| mapstruct | 7.0 MB | 5.5 MB | 5.6 to 7.2 MB |

- CPU, best of 5, same machine and load: fmtout 2223 to 2388 ms, heapsort 1985 to 2096 ms, bintrees 2951 to 3071 ms (4 to 7% slower). jsondec, pingpong, workerpool unchanged. Mapstruct 5% faster. With the first 32 MiB, the slowdowns were larger. Fewer huge pages mean more TLB misses in allocation-heavy programs.
- Verdict: candidate. It halves the RSS of small programs. Its CPU cost (up to about 5%) is near the noise of these runs, but above the 2% rule. It needs a perfcmp with the change behind an opt-in before a decision. A smaller range (the first 4 MiB chunk only) may keep most of the RSS gain with less TLB cost.