Skip to Content
marmot

Date: 2026-11-18. Status: recommendation to drop the held commit (8b7fb305).

Question

The held commit collects before a large allocation (over 32 KiB) that crosses the trigger, instead of after it. It lowered peak RSS (wordfreq 534 to 397 MB). But it doubled or tripled the collection counts of some programs, and mapstr lost 4 to 8% CPU. The rule is CPU and wall within 2% in perfcmp. Is there a version that keeps the RSS and not the collections, for example a pacer fix?

Measurements

Release builds, linux/amd64 host, peak RSS in MB (best of 3, fork and wait4, no floor), collection counts from MARMOT_GCTRACE and GODEBUG=gctrace=1. Variants:

  • main: collect after the allocation.
  • cur: the held commit (collect first).
  • v2: cur, only when the object takes the heap past the goal. Also half its size must be allocated since the last collection.
  • v3: cur, and the next goal counts the pending object as live.
Programmaincurv2v3go
wordfreq534 MB, 9 gc397, 18397, 18534, 9401, 9
stringsearch26, 2415, 6615, 6619, 2423 to 30, 24 to 26
regexpbench80, 1962, 2661, 2275, 1958 to 67, 13
jsonenc45, 2241, 2441, 2445, 2237 to 40, 10
nsieve47, 429, 829, 728, 4364 to 382, 4
mapstr110, 3111, 6111, 5110, 398, 4
generic184, 15196, 38218, 21225, 15265, 16 to 19

v3 confirms the mechanism: with the pending object counted in the goal, the counts return to main, and so does the RSS. The RSS gain of the held commit comes only from the extra collections. A pacer change cannot give one without the other.

Causes, per program

An allocation trace (a print in alloc_slow for objects of 1 MiB or more) shows what each program does:

  • wordfreq: not a pacing problem. bytes.growSlice does append([]byte(nil), make([]byte, c)...). Go compiles this to one allocation. Marmot allocates the make temporary and then the append result: two 128 MiB arrays at the last doubling. The collection after them counts the temporary, so the goal is 655 MB where go's is 384 MB. Codegen has the fix behind MARMOT_APPENDMAKE (default off). With it: 547 to 410 MB, 9 collections, output identical. The flip of MARMOT_APPENDMAKE is a front end task.
  • stringsearch: allocates 4 MiB objects in a loop. main overshoots the goal by one object before it collects. The collection-first variants keep the heap under the goal, but then a cycle holds fewer objects, so collections go from 24 to 66. main is already at parity with go (24 collections, 26 MB against 23 to 30 MB).
  • nsieve: already 0.13x of go (marmot stores []bool as bits). Not a target.
  • regexpbench: ReplaceAllString and FindAllStringIndex grow slices by 1.25x. The collection that a growth triggers counts the old and the new array. This is the one program where collecting first pays: 80 to 61 MB for 19 to 22 collections (v2).
  • jsonenc: 45 to 41 MB for 22 to 24 collections. Small.
  • mapstr, generic: the collection-first variants only add collections, and generic gets worse RSS.

Recommendation

  1. Drop the held commit and the v2 guard. After APPENDMAKE, the remaining gain is regexpbench (about 18 MB) and jsonenc (about 4 MB). The cost is extra collections in other programs, which the 2% rule does not allow (mapstr +4 to 8% CPU in the first gate).
  2. Do not change the pacer. main already counts the same live heap as go. The gaps above go come from allocation volume (APPENDMAKE, fmt boxing in sortslice) and false retention (jsondec dead locals), which the compiler owns.
  3. Regexpbench (1.2x of go) stays open. A targeted fix belongs in growslice. When append grows a slice whose old array is dead after the copy, nothing can know that at the allocation. Not worth a runtime heuristic now.

Critique

  • All RSS numbers are best of 3 on a shared host. The differences above 10% repeat in both jobs. The smaller ones may be noise.
  • The comparison with go uses one go version (1.27) and default GOGC.
  • v1 (past the goal only) is not in the second job. The first job showed it equal to cur on every program but generic and regexpbench.

On this page

Was this page helpful?

Report an issueOpen issues