# Front end and code generator (/docs/experiments/frontend)

This page records the experiments and optimizations in the driver and the code generator (cmd/marmot, internal/driver, internal/codegen) from 13 to 16 November
2026. Each section says what changed, why, how it was measured, the verdict and the next step.

Terms:

- A switch is an environment variable that turns a change on. A change that can alter program behavior or performance lands behind a switch, default off.
- The default flips only after `tests/perfcmp` exits 0 in dev, O2 and release. perfcmp builds the same programs with and without the switch and compares wall time, CPU time, peak RSS and size. Its verdict is ok, WORSE or INCONCLUSIVE. INCONCLUSIVE means that the noise of a mode was above 2%.
- Dev builds use tier0, the fast code generator. O2 and release builds use LLVM.
- Measurements on linux/amd64 come from a shared Linux machine through a job queue. Measurements on darwin/arm64 come from a development machine.

## Summary [#summary]

| Change | Switch | Verdict |
| --- | --- | --- |
| Line-only source locations in optimized builds | MARMOT_LOC_COLS=1 keeps columns | Flipped |
| Link parts in a fixed order | MARMOT_PART_ORDER=1 | Opt-in, gate running |
| wasm gcdata with 4-byte pointer words | none (bug fix) | Landed |
| ptrdata from the type layout | none (bug fix) | Landed |
| rt_wb_kind in the entry module | with MARMOT_WB | Landed |
| wasm pc table through source maps | MARMOT_WASM_HOSTCALLERS=1 | Landed |
| Pointer-free data sections | MARMOT_NOPTR=0 turns off | Flipped |
| Scan records for package variables | MARMOT_GCVARS=0 turns off | Flipped |
| Skip dominated nil checks | MARMOT_NILDOM=1 | Opt-in, gate queued |
| Package init code in its own section | MARMOT_INITSECT=1 | Opt-in, runtime gate |
| Position dependent executables | MARMOT_NOPIE=1, -buildmode=pie | Opt-in |
| One home for large shared functions | MARMOT_HOME_INSTANCES=1 | Opt-in, to measure |
| Constant boxes named by content | none | Dropped |
| Card marking write barriers | MARMOT_WB=cards, cardstub, cardflag | Opt-in |
| Per-function SSA statistics | MARMOT_SSASTATS=FILE | Measurement aid |
| Type descriptor owners in release builds | none | Landed |
| Constant literal images | MARMOT_LITCOPY=0 turns off | On by default |
| Stack buffer for append groups | MARMOT_APPENDSTACK=1 | Opt-in, gates queued |
| GC pointers in the go dialect (nil check) | with MARMOT_GCPTR=1 | Partial fix landed |

## Line-only source locations [#line-only-source-locations]

What: in optimized builds (-O 1 and up, -release) every op location carries the line only, with column 1. Dev builds are not affected.

Why: tracebacks and DWARF line tables use lines only. About half of the location aliases in the MLIR differed only by column. Each distinct location costs parse time and a DILocation in LLVM.

Measurement: tuios -O 2, cold, with MARMOT_IRSTATS. MLIR text 688.4 MB to 639.2 MB (-7.1%). Location alias bytes 88.5 MB to 40.6 MB. Distinct DILocations before the optimizer 1.56 M to 0.98 M (-37%), after it 1.60 M to 1.12 M (-30%). __text is identical (19904444 bytes). perfcmp -b-env MARMOT_LOC_LINEONLY=1 -modes O2,release on linux/amd64 at fed86223: verdict ok, exit 0. Geomean wall time 0.977 (O2) and 0.985 (release), CPU 0.975 and 0.987, RSS 0.999 and 1.001, noise 1.015 and 1.006. Dev builds were checked by byte comparison instead: the 11 bench programs and hello are byte-identical with and without the switch. sketch and tuios differ only in .marmot_pcln, see "Dev pc tables name local symbols by cache key" below.

darwin/arm64 (evidence, backend at 575eba2e, A with MARMOT_LOC_COLS=1): verdict ok, geomean wall 0.994 (O2) and 0.999 (release), RSS 1.000.

Verdict: flipped (08db8598). MARMOT_LOC_COLS=1 keeps columns.

Next: none.

## Link parts in a fixed order [#link-parts-in-a-fixed-order]

What: large packages are generated as several modules (parts). With MARMOT_PART_ORDER=1 the driver links the objects of the parts in package and part order.

Why: a part gets its module number when its package finishes code generation, and generation runs in parallel. The link order followed those numbers. So two cold builds of one commit gave different binaries. The layout of .text, .rodata and .data and the pc table changed from run to run. In tuios -O 2, 13 of 506 part jobs swapped. This also adds layout noise to every perfcmp.

Measurement: TestReproducibleBuild builds a program twice cold with small parts in dev and O2 and compares the binaries. It fails without the fix (first difference at byte 320) and passes with it. With the switch, two cold dev builds of tuios and of sketch in one root with one environment are byte-identical. With the switch off, the output is unchanged: the bench programs and sketch are byte-identical to the previous commit in all three modes. perfcmp -b-env MARMOT_PART_ORDER=1 at ca2418cd, first run: INCONCLUSIVE (noise 1.020 to 1.022), geomean wall 0.999 (dev), 1.003 (O2), 1.009 (release).

Verdict: opt-in (ca2418cd). The perfcmp rerun is in the queue.

Next: flip on exit 0.

## wasm gcdata with 4-byte pointer words [#wasm-gcdata-with-4-byte-pointer-words]

What: the gcdata bitmap of a type descriptor has one bit per pointer-sized word of the target. On wasm a pointer is 4 bytes, and int and uintptr are 8 bytes.

Why: the code generator used 8-byte words everywhere. On wasm a pointer at an offset of 4 mod 8 shared bit 0 with the pointer before it, so the collector never scanned it. A closure context \{F, X0\} lost its captured variable after a collection.

Measurement: a program keeps 5000 closures in a slice and runs runtime.GC. Before the fix, 950 of 5000 closures returned a wrong value. After it, 0 did. A program with 100000 goroutines and captured variables: the sum was wrong before and right after. Native output is byte-identical (bench programs and sketch in dev, O2 and release, tuios dev). TestGCLayout fails on wasm with 8-byte words.

Verdict: landed (a3f3d429). Tests tests/run/gc/closure_gc and goroutine_sum (fed86223).

Next: none.

## ptrdata from the type layout [#ptrdata-from-the-type-layout]

What: ptrdata (the bytes of a value that can hold pointers) comes from the type layout. Before, it came from the last pointer word that the word list held.

Why: the word list stops after 8192 entries in very large arrays. So the ptrdata of such a type was short: [2097152]*node had 65544 bytes instead of 16777216 (32772 instead of 8388608 on wasm). The checker (marmot verify, gccheck) found it. Such types have no bitmap and are scanned in full, so collection was safe. But reflect.ArrayOf and StructOf compute PtrBytes from ptrdata.

Measurement: of 36 perfcmp program builds in dev, O2 and release, 33 are byte-identical. mapstr differs in one descriptor, type:[1000000]string, with ptrdata 131080 to 15999992. .text is unchanged. perfcmp of mapstr: dev wall 0.993, O2 1.034 with noise 1.048 (INCONCLUSIVE). The runtime only tests ptrdata for zero, which both values pass, so mapstr runs the same code.

Verdict: landed (1e5d699c).

Next: none.

## rt_wb_kind in the entry module [#rt_wb_kind-in-the-entry-module]

What: when MARMOT_WB is set, the entry module defines the constant rt_wb_kind. Its value is 1 for the flag barrier (and every mode on wasm) and 2 for card marking.

Why: concurrent marking (MARMOT_GC_CONC=1) in a program without write barriers frees live objects. The runtime holds a weak 0, so it can refuse concurrent marking when the program has no barriers.

Measurement: hello in dev, O2 and release: the entry object has a strong rt_wb_kind with the right value, and none without MARMOT_WB. TestWBKind.

Verdict: landed (4c9190a6). Default output unchanged.

Next: none.

## wasm pc table through source maps [#wasm-pc-table-through-source-maps]

What: for wasm programs built for hosts that provide stack imports (MARMOT_WASM_HOSTCALLERS=1, the playground), the pc table comes from the final module. marmot-pcln writes a source map of the linked module from its DWARF. wasm-opt carries the map through its passes. marmot-pcln then reads functions from the final code and name sections, and lines from the map.

Why: wasm-opt leaves the DWARF stale, so a table read from it had wrong lines.

Measurement on a small fmt program: 2434 functions, 2221 with an entry line, 14705 rows. The table from DWARF had 1744 of 2442 functions with lines and 10900 rows. An end to end check used the runtime's host callers. runtime.Caller, CallersFrames and a nil map panic traceback give the right files and lines in dev and release.

Verdict: landed (80ccafba), together with the runtime side.

Next: the playground host provides the two imports.

## Pointer-free data sections and scan records [#pointer-free-data-sections-and-scan-records]

What: MARMOT_NOPTR=1 puts package variables, static literal objects and large zero values without pointers in sections that the collector does not scan. These are as gc's noptrdata and noptrbss. On Mach-O they are __DATA,__noptrdata and __noptrbss. On ELF each variable has one section, and a linker script gathers them. MARMOT_GCVARS=1 adds a scan record (address, words, bits) for each variable with pointers of 8 to 4096 words. The runtime then scans it precisely (LLVM builds only).

Why: the collector scanned all Go data conservatively, most of it free of pointers.

Measurement: tuios -O 2 on darwin/arm64: conservatively scanned Go data 37.5 MB to 1.25 MB. A small fmt program dev: __data 225968 to 141280 bytes, __bss 1151009 to 100897 bytes. GC stop times, tuios dev, 50 MB allocation flood, two runs each: off p50 3185 and 3808 us, p99 3766 and 35469 us. On p50 2400 and 2264 us, p99 2801 and 2916 us. RSS is unchanged (tuios dev, medians of 5: 76.9 MB off, 76.6 MB NOPTR, 76.4 MB NOPTR and GCVARS). The conformance suite with every frontend switch on passes, apart from failures caused by MARMOT_NOPIE (see below).

darwin/arm64 perfcmp, as evidence and not as a gate (A and B in one root, backend at 575eba2e). Bench programs and sketch geomean wall: 0.990 (dev), 0.992 (O2), 0.987 (release). tuios 0.959 (dev), 0.954 (O2, verdict ok), 0.952 (release). RSS 0.996 to 1.003. The first linux/amd64 perfcmp at cbe472bd failed to judge: a tuios release build hit the backend's 300 s guard under host load 8 to
10. Its geomeans before that were 0.995, 1.007 and 0.991.

linux/amd64 perfcmp at bd3fa968 (with the build time limits raised): verdict ok, exit 0, geomean wall 1.003 (dev), 0.988 (O2), 0.990 (release), RSS 1.000 to 1.001, noise about 1.01.

Verdict: flipped (21146e69). MARMOT_NOPTR=0 and MARMOT_GCVARS=0 turn them off.

Next: flip on exit 0.

## Skip dominated nil checks [#skip-dominated-nil-checks]

What: MARMOT_NILDOM=1 emits no nil check of a value when an earlier check of the same value dominates it.

Why: code after a check runs only when the value is not nil. tier0 does not remove such checks itself.

Measurement: a small fmt program: nil checks in the MLIR 5003 to 2471, MLIR bytes -3.8%, dev __text -0.85%. O2 is unchanged (LLVM removed them later).

darwin/arm64 perfcmp (evidence): verdict ok, geomean wall 0.999 (dev), 1.003 (O2), 0.997 (release), RSS 1.000 to 1.001, tuios dev binary 56.3 MB to 55.9 MB.

Verdict: opt-in. The linux/amd64 perfcmp -b-env MARMOT_NILDOM=1 is queued.

Next: flip on exit 0.

## Package init code in its own section [#package-init-code-in-its-own-section]

What: MARMOT_INITSECT=1 puts package init functions and the closures nested in them in their own text section (Mach-O __TEXT,__StaticInit, ELF .text.startup.SYM), as C++ static initializers.

Why: init code runs once at startup and touches pages all over the text.

Measurement: every package init lands in one run at the end of __text. tuios --version peak RSS on linux/amd64, dev: 58 to 60 MB default, 50 to 52 MB with the switch.

Verdict: opt-in. The runtime owns its gate, which comes first in the startup order.

Next: the runtime's perfcmp.

## Position dependent executables [#position-dependent-executables]

What: MARMOT_NOPIE=1 links ELF executables position dependent (-no-pie), as go build does on linux. -buildmode=pie keeps a position independent executable with packed relative relocations (RELR).

Why: a PIE carries a relative relocation for every address in its data. ld.so applies them at startup and writes all of .data.

Measurement: a small fmt program, O2: 1052472 bytes as PIE, 804560 position dependent, 808592 as PIE with RELR. tuios dev: 92.9 MB PIE, 79.6 MB position dependent (go: 70.1 MB). tuios --version peak RSS: 38 MB with INITSECT and NOPIE, 38 to 41 MB with INITSECT and RELR PIE. The first conformance run with the switch failed 8 tests (runtime.FuncForPC, runtime.Caller, tracebacks). The pc table builder gave address 0 to functions that the linker removed. That address wrapped under the position dependent base. After that fix in marmot-pcln, the same tests pass.

Verdict: opt-in. Startup gate order: INITSECT, then RELR PIE, then NOPIE only if RELR loses.

Next: RELR PIE against INITSECT.

## One home for large shared functions [#one-home-for-large-shared-functions]

What: MARMOT_HOME_INSTANCES=1 (whole program release builds) emits each shared function of more than 12 SSA instructions once, in an instances module. The other modules declare it. Smaller ones keep their linkonce_odr copies.

Why: every module that uses a generic instance or wrapper compiles its own copy.

Measurement: a small fmt program: instances module 990 KB, __text 278108 to 278400 bytes. tuios and crypto/ecdsa did not link: the whole program import lost local constants of imported bodies. That bug is fixed in the backend.

Verdict: opt-in.

Next: measure tuios release build time and size with the switch.

## Constant boxes named by content (dropped) [#constant-boxes-named-by-content-dropped]

What: constant boxes (a constant converted to an interface) were to be named by content, as linkonce_odr globals, in every mode.

Why: a wasm release build of cmd/marmot failed to link: private .box.N globals were undefined in other objects.

Measurement: hello -release __text +6.7%.

Verdict: dropped. The cause was in the backend's whole program import, which now keeps local constants. The wasm build links with that fix.

## Card marking write barriers [#card-marking-write-barriers]

What: write barriers for concurrent marking. MARMOT_WB=1 tests a flag and calls rt_wb. MARMOT_WB=cards marks a card byte per store into a possible heap slot, only when the card is clean. It skips stack slots, globals and values that point at no heap. It also skips stored values that are allocation results (rule B), and values of type *runtime.g and *runtime.sudog. MARMOT_WB=cardstub marks through a call the backend lowers to a flag test and a register stub. MARMOT_WB=cardflag inlines only the flag test.

Why: concurrent marking needs a barrier. Card marking keeps the store path short and moves the work to the collector.

Measurement, tuios -O 2 __text: +12.1% with the flag barrier and +5.4% with one card per pointer word. One card per small object gives +4.8%, and the clean test +6.3%. perfcmp on darwin/arm64 (-b-env MARMOT_WB=cards): O2 WORSE, geomean time 1.040, cycles 1.043. Release 1.003 and 0.999. Instructions retired at GOMAXPROCS=1 show that the WORSE lines of iface and spectralnorm are layout (1.0000 and 0.9999). One earlier skip (stores into objects allocated since the last call) was unsound with card marking and was removed.

Verdict: opt-in.

Next: the runtime's concurrent collector decides which barrier becomes the default.

## Per-function SSA statistics [#per-function-ssa-statistics]

What: MARMOT_SSASTATS=FILE writes, for each function and kind of SSA instruction, the number of instructions and the MLIR values and blocks emitted.

Why: to find where generated code is large.

Measurement: tuios -release: 52897 functions, 3.77 M SSA instructions. The backend joins it with its IR counts.

Verdict: measurement aid, off by default.

## Type descriptor owners in release builds [#type-descriptor-owners-in-release-builds]

What: in release builds, the module of a package defines the descriptors of its package level named types and their pointers. The method tables and wrappers go with them. The other modules declare them.

Why: every module defined its own copies.

Measurement: tuios -release front end output 836 MB to 507 MB (globals 314 MB to 87 MB, wrapper definitions 69536 to 13293). cmd/marmot -release builds in 55 s against 77 s on darwin/arm64, binary 12.97 MB to 12.66 MB.

Verdict: landed (caefcaa5).

## Constant literal images [#constant-literal-images]

What: constant composite literals and map literals are built from static data instead of stores.

Why: smaller and faster code for configuration tables.

Measurement: tuios dev binary 62.12 MB to 61.61 MB, __text 39.29 MB to 38.00 MB. A bug turned them off for a day: a constant store into a field after that field's own literal was dropped. Such objects now get no image. Gate with the switch forced on: conformance 1521 of 1534. The failures waited for a tool install. Fuzz: 300 dev and 100 release programs, 0 differences.

Verdict: on by default (2f2b29bb). MARMOT_LITCOPY=0 turns them off.

## Dev pc tables name local symbols by cache key [#dev-pc-tables-name-local-symbols-by-cache-key]

What: a finding, no change. tier0 renames the local symbols of modules that have fallback functions to NAME.t0.KEY, where KEY starts with the module's cache key.

Why it matters: every MARMOT_ environment variable and the root path go into the cache keys. So a dev build with any switch set differs from one without it in .marmot_pcln, even when the code is the same. Byte comparisons of dev builds must use one root and one environment, or compare sections other than .marmot_pcln.

Next: none planned.

## Stack buffer for append groups [#stack-buffer-for-append-groups]

What: MARMOT_APPENDSTACK=1 gives a group of append sites that carry one local slice a 32-byte frame buffer. A growth from capacity 0 to a length that fits takes the buffer instead of growslice, with the same capacity growslice would give. The design follows Go 1.26's append buffers. The rule has four parts. There is exactly one nil entry, and no phi when the entry is in a loop. An operand feeds at most one site, but a loop header phi may feed one site inside its loop and others after it. Only the group, len, cap, copy, reslices and element loads and stores use the group values. Off on wasm, in recursive functions, with region allocation, in-place append reuse and MARMOT_GCPTR=1.

Why: allocation and GC bound the library-heavy bench rows (jsondec: about 50% of the profile). Short local slices built by append are common.

Measurement: a line splitting benchmark, with a local []int, a loop append and a tail append, and 5 million calls. Heap allocations go from 15 M to 10 M in dev, O2 and release. Single runs: O2 612 ms to 584 ms, release 474 ms to 411 ms. A capacity and adversarial test program prints the same output as go, with the switch off and on, in dev, O2 and release. TestAppendStackSites fails when any one of the rules is removed. The runtime and verify reviewed the design. Their points are in the design note.

darwin/arm64 perfcmp (evidence): geomean wall 1.001 (dev), 0.998 (O2), 1.006 (release), tuios O2 0.999 (verdict ok), RSS 1.000 to 1.001, sizes unchanged. Verify signed off the rule for gating. 13 adversarial programs in verify/testdata/progs/appendstack.go match go in dev and the go dialect. They match plain and with POISON and GCSTRESS, with and without the switch.

Verdict: opt-in (1b32f0ec). Conformance and fuzz with the switch forced on and the linux/amd64 perfcmp are queued.

Next: gate, then a second switch that matches Go 1.27's capacities.

## Append capacities differ from Go 1.27 [#append-capacities-differ-from-go-127]

What: a finding. After small local appends, Go 1.27 reports capacities from its 32-byte stack buffer. One int append gives cap 4 (marmot 1), and one byte gives cap 32 (marmot 8). Three appends in a loop give cap 3 (marmot 4). Both are legal (the spec only requires cap >= len), but a program that prints cap prints different output than go.

Verdict: open. A separate switch will match Go's capacities, gated with conformance tests that print cap and compare with go.

## GC pointers in the go dialect [#gc-pointers-in-the-go-dialect]

What: MARMOT_GCPTR=1 puts GC pointers in address space 1 for statepoints. With it, -release builds, which use the go dialect, failed to parse. go.nil_check takes an address space 0 pointer. The nil check now gets an address space 0 copy for the test only.

Why: the runtime measured jsondec peak RSS at 2.16x go (68 MB against 31 MB). The conservative stack scan keeps dead pointer locals of long-running frames. Precise liveness needs GC pointers in release builds.

Measurement: jsondec -O 2 with MARMOT_GCPTR=1 builds and runs. -release still fails at other go dialect ops (about 20) whose pointer operands are address space 0 in the dialect.

Verdict: partial fix landed (13a23248). Casting the other operands in the code generator would hide GC pointers from the statepoints, so the dialect ops need to accept GC pointers.

Next: the backend changes the op types.

## Research and design notes [#research-and-design-notes]

The gap analysis, sources and candidate list are in frontend-research.md. The design of the append buffers with the review points is in frontend-design-appendstack.md.

## Allocation gap in fmt calls (sortslice) [#allocation-gap-in-fmt-calls-sortslice]

What: a finding, with gates queued. The runtime measured sortslice with 12.0 M heap allocations against go's 7.0 M. The program calls fmt.Sprint("n", i%1000) 4 million times.

Measurement (mallocs per call, linux/amd64):

| Build | Sprint("n", i%1000) | Sprint("n") | boxing i%200 |
| --- | --- | --- | --- |
| go | 1.74 | 0.00 | 0.00 |
| marmot dev and O2 | 2.74 | 2.00 | 0.00 |
| marmot release | 3.00 | 2.00 | 1.00 |
| marmot dev and O2, MARMOT_LIFETIME=all | 1.74 | 1.00 | 0.00 |
| marmot release, MARMOT_LIFETIME=all | 2.00 | 1.00 | 1.00 |

Causes: (1) the variadic []any array of every fmt call is on the heap. The escape analysis switches are off by default ("passed to fmt.Sprint, which may keep it"). The three switches MARMOT_XPKG_ESCAPE, MARMOT_ESCAPE_SUMMARY and MARMOT_ESCAPE_EXT together move it to the stack (no single one or pair does). (2) release builds box small integers on the heap: the backend's go.box lowering lacked gc's static words (fixed behind MARMOT_BOXSCALAR=1 in the backend). (3) one-byte strings do not come from the runtime's static table. The runtime fix is pending. It does not affect sortslice, whose strings are 2 to 4 bytes.

Verdict: the three escape switches are queued as one gate (conformance and fuzz forced on, perfcmp, verify review). The stack conversion and memory reuse switches stay off.

## Self-host layout shift [#self-host-layout-shift]

What: a finding. cmd/marmot built by a Go-built marmot and by a marmot-built marmot differed by a 16 to 32 byte layout shift. The MLIR of all 320 modules, the link lines and the object code of all objects but one are identical. The one difference: in one split part of net/http, one function (NewRequestWithContext, specialized) has the same instructions in a different block order.  Control runs settle it: the same batch under the same names twice, and with -j 8 and -j 16, gives identical objects. The same contents under other file names and keys change 4 of 381 objects. So the backend's output depends on its input file names or keys, and those differ because the compiler's identity is part of the cache key. Not a miscompile.

Next: the backend removes the dependence on names.