Skip to content

skills: a collector-off run on a machine reclaiming its pages reads neither its allocation nor a steady count #2368

Done

Description

@OmarAlJarrah

Problem

morphic-measuring-performance/references/finding-cost.md assumes that a run with the collector off keeps in memory what it allocates. Two rules rest on that:

  • count-on-one-thread: "Set GOMAXPROCS=1 GOGC=off for an instruction count over a compile ... A spec too large to hold uncollected keeps GOMAXPROCS=1 alone and says so." Nothing says how to tell whether a spec is held. That depends on the memory the machine has free at the time, not on the spec alone.
  • resident-set-without-collector: "With GOGC=off nothing is freed, so the maximum resident set /usr/bin/time -l prints beside an instruction count is every byte the run allocated."

On a loaded machine, the system reclaims the run's pages, and both readings move. These runs compiled the golden spec (cloudflare/api-schemas @904c5434) with GOMAXPROCS=1 GOGC=off /usr/bin/time -l <bin> compile -o /dev/null openapi.json, alternating two builds of the work on #2354 (b3fb238, which that PR's branch does not hold yet, and a working tree on it) and dropping each binary's first run. The machine ran macOS with 12 cores and 36 GB, at a load average of 40 to 100, on 2026-11-30:

build  max resident set  instructions retired
base      4,906,549,248       106,874,591,544
head      2,094,333,952       110,618,645,153
base      1,001,177,088       117,755,821,755
head      1,149,353,984       120,346,723,432
base        921,452,544       122,469,150,698
head        814,841,856       124,657,562,111

The same command, run a day earlier on two other builds of that work (4de1117, on the branch, and a head on it), read:

build      instructions retired  max resident set
4de111770       105,618,380,574     6,530,056,192
head            106,371,027,627     6,680,756,224
4de111770       105,863,666,945     6,529,859,584
head            106,869,563,258     6,678,085,632
4de111770       106,208,205,304     5,180,309,504
head            106,968,593,242     6,179,536,896

The compile allocates about 6.5 GB uncollected. Over six runs, the resident set fell from 4.9 GB to 0.8 GB, so it measured what the system left resident, not the allocation. As it fell, the instruction count rose in run order on both builds alike, from 106.9 G to 124.7 G (17%), where the earlier runs, at 5.2 to 6.7 GB, stayed within 1.3%. Nothing in the rules checks that a reading came from a run that held. Nor do they say what to do once a spread is wider than any gap the comparison could quote.

Direction

A draft:

  • In count-on-one-thread, say how to tell that a collector-off run held. Its maximum resident set agrees across the runs of one build to within a few percent, and with that of a run on a quiet machine. Drop a reading from a run that did not hold. Then take a spec small enough to hold, or GOMAXPROCS=1 alone with the spread the rule states for it.
  • In resident-set-without-collector, limit the reading to a run that held, by the same check.
  • Beside each cost figure, give the load average at both ends and each side's spread. Where a side's spread is wider than the gap, claim nothing. Either alternate paired runs on a smaller spec and quote medians, or measure later on a quieter machine. Say which was done.

Out of scope

Related: #1470, #2078

Priority: P4, rule 1 (housekeeping): a skills change that alters no lowering, validation, IR or emit-contract behaviour. The command above → max resident set 0.81 to 4.91 GB and instructions 106.9 to 124.7 G over six runs (spec @904c5434, morphic @b3fb23899). git grep -n -i -E 'page|swap|memory pressure' origin/main -- .claude/skills/morphic-measuring-performance → no match (morphic @4a7a384c9).

Activity

  1. added
    type:bug
    priority:P4
    on Nov 30, 2026
  2. OmarAlJarrah commented on Nov 30, 2026

    @OmarAlJarrah
    MemberAuthor

    One more case of the same mechanism. Profiling compilers/openapi/e2e on a macOS development machine attributed about 20% of the package's CPU profile to platform overhead (system calls and the memory allocator's page handling) that the Linux CI runner does not show. So a wall-clock or profile share measured locally overstates what CI will see, and the gap is not constant across packages. The skill could say to project CI times from instruction counts, or from a ratio against a CI run of the same package, rather than from local wall-clock time.

  3. OmarAlJarrah commented on Dec 2, 2026

    @OmarAlJarrah
    MemberAuthor

    More evidence for the same rule, from a machine with 12 cores at a load average of 60 to 117 (macOS, 2026-12-01): over repeated runs of the golden-spec compile, the instruction counts of one build swung about 16%, and the maximum resident set could not be read at all, for the reason this issue gives. A 1.05x difference between two builds stood only after three alternating pairs, each build run in turn, with the medians quoted; a single pair, or a block of one build's runs and then the other's, would have read either way.

    So the method asked for here should also say what to do when the spread exceeds the gap: alternate paired runs, quote the medians and the load at both ends, or claim nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P4type:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions