Skip to content

gc: cap the adaptive tenuring threshold's occupancy rule at 3, keep the survival-rate lock - #14685

Merged
proggeramlug merged 8 commits into
mainfrom
perf/gc-tenuring-cap
Nov 14, 2026
Merged

proggeramlug merged 8 commits into
mainfrom
perf/gc-tenuring-cap

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What

The copying minor's promotion age S has two rules in crates/perry-runtime/src/gc/tenuring.rs:

  • the occupancy rule: S = 1 + desired / influx, debounced, held at the floor of 2 until a survivor round has been rated;
  • the survival-rate lock: S = 1 when a substantial fresh cohort comes back at least 90 % alive, plus the sweep seed.

When few objects survive, the occupancy rule climbed to 4, so every survivor was copied up to three times before it could be promoted. This PR caps the occupancy rule at OCCUPANCY_MAX_SURVIVALS = 3. The cap sits at the retune callsite, like the floor: compute_target_survivals(..).max(OCCUPANCY_MIN_SURVIVALS).min(occupancy_max_survivals()).

These are unchanged:

  • the pure function (the sweep seed's != 1 test reads it);
  • the lock and its latch and unlock conditions;
  • the unlock step to 2;
  • the sweep seed;
  • the parent probe.

Controls:

  • PERRY_GC_TENURING_SURVIVALS_MAX=<n> is a runtime switch, read once, clamped to 2..=4, with one warning when it clamps. =4 is main's behaviour.
  • PERRY_GC_TENURING_SURVIVALS=<n> still pins S for every minor and overrides both rules.
  • Both are documented in docs/src/internals/garbage-collector.md (aging section and "Supported controls").

Tests:

  • The tests that assert the old climb run with the ceiling at 4. That keeps the switch's old state exercised in the required cargo-test, per the AGENTS.md knob policy.
  • New tests cover the default ceiling, the lock under the default, the clamp, the pin's precedence, and the ceiling on real copying minors.
  • dying_survivor_cohorts_do_not_lock runs at ceilings 2, 3 and 4.
  • No lock test was weakened.

Numbers

Measured on qb10 with one release build of 8958b64 (this branch, main merged). Every program was compiled once, and all arms ran on the same binary via PERRY_GC_TENURING_SURVIVALS_MAX:

  • m4 = main's behaviour;
  • m3 = this PR's default;
  • m2 = control.

Method: instructions:u x3 (taskset 24-31) and peak RSS x5 (/usr/bin/time %M). The program set is from the tenure2 measurement: chess, a medium-lived record benchmark, the GC-ratchet probes and the app-pattern kernels, scaled.

program instr M m4 (main) m3 (this PR) Δ % m2 Δ % RSS KiB med m4 m3 Δ KiB m2 Δ KiB
chess search 250000 11 577.741 11 488.901 -0.767 11 396.781 -1.563 23 552 23 552 0 23 552 0
chess perft 4 251.051 251.050 -0.000 251.051 +0.000 15 360 15 360 0 15 360 0
chess evaluate 100000 1 187.721 1 187.721 +0.000 1 187.721 +0.000 15 360 15 360 0 15 360 0
chess legal 10000 347.458 347.459 +0.000 347.458 +0.000 15 608 15 612 +4 15 604 -4
medium2 W=1k 12 830.649 12 731.473 -0.773 12 631.804 -1.550 15 872 15 872 0 15 872 0
medium2 W=2k 13 966.833 13 867.485 -0.711 13 767.659 -1.426 16 384 16 384 0 16 384 0
medium2 W=3k 12 976.391 12 902.557 -0.569 12 829.209 -1.134 22 528 22 528 0 22 528 0
medium2 W=5k 14 284.049 14 284.018 -0.000 14 284.063 +0.000 70 720 70 492 -228 70 720 0
medium2 W=10k 14 471.002 14 471.006 +0.000 14 454.950 -0.111 95 380 95 412 +32 97 380 +2 000
r02x survivor promotion 4 122.102 4 122.108 +0.000 4 122.120 +0.000 111 112 111 116 +4 111 112 0
r12x large live set 7 871.750 7 871.725 -0.000 7 871.728 -0.000 217 156 217 156 0 216 900 -256
ksplitx 7 240.331 7 240.310 -0.000 7 240.329 -0.000 245 668 245 672 +4 245 668 0
kcsvx 3 171.744 3 171.720 -0.001 3 171.785 +0.001 187 024 187 028 +4 187 028 +4
kpromx 14 592.643 14 592.640 -0.000 14 592.642 -0.000 11 776 11 776 0 11 776 0
r01x 2 083.349 2 083.352 +0.000 2 083.353 +0.000 13 056 12 800 -256 13 056 0
r05x 8 521.195 8 521.179 -0.000 8 521.193 -0.000 12 544 12 544 0 12 544 0
r06x 5 413.169 5 413.167 -0.000 5 413.177 +0.000 12 032 12 032 0 12 032 0
r08x 14 373.624 14 374.000 +0.003 (spread 0.012) 14 373.889 +0.002 17 152 17 152 0 17 152 0
kbufx 9 375.016 9 375.019 +0.000 9 375.018 +0.000 55 040 55 040 0 55 040 0
kclonex 2 900.198 2 900.194 -0.000 2 900.197 -0.000 12 032 12 032 0 12 032 0
sstrx 7 420.841 7 420.839 -0.000 7 420.831 -0.000 12 032 12 032 0 12 032 0
sjsonx 17 430.637 17 430.636 -0.000 17 430.636 -0.000 48 640 48 640 0 48 640 0

Chess search peak RSS, x20 per arm, interleaved:

arm median min max modes
m4 23 552 23 296 23 552 19x 23 552, 1x 23 296
m3 23 552 23 296 23 552 19x 23 552, 1x 23 296
m2 23 552 23 296 23 552 18x 23 552, 2x 23 296

Reading:

  • m3 against m4: no program is worse.
    • Instructions: the largest increase is r08x at +0.003 %, inside its own 0.012 % run-to-run spread.
    • RSS: the largest increase is +32 KiB on medium2 W=10k (m4 95 120..95 416, m3 95 376..95 416), inside one 256 KiB step. Search's x20 distribution is identical.
  • Gain: chess search -0.77 %, medium2 W<=3k -0.57..-0.77 %.
  • Outputs are identical across arms and runs. sstrx and sjsonx print an elapsed-ms line with no unit, which changes every run in every arm (old vs old: 334 vs 353, 964 vs 1008); their checksum lines are identical in all runs.
  • The m4 arm reproduces main. Measured on the branch before the main merge (fe6cd42), against main 908ecff compiled from the same sources: within +0.000..+0.004 % instructions on all 22 runs, same outputs, RSS within one page.

Why the ceiling is 3, not 2. A ceiling of 2 roughly doubles the gain (search -1.56 to -1.60 %). It was rejected for peak RSS:

  • +64 KiB on chess search on the earlier build (fe6cd42, x20 interleaved: median 23 524 vs 23 460, a consistent 16-page mode shift);
  • +2 000 KiB on medium2 W=10k on this build.

At S=2, cohorts that a third survivor round would have let die are promoted instead: search promotes 10.65 MB against 10.49 MB.

chess perft, evaluate and legal do not gain, at either ceiling. On those workloads S rises above 2 only on the last minors, which copy almost nothing; copied bytes are equal across arms in a diagnostic build. The PERRY_GC_TENURING_SURVIVALS=2 pin did gain -0.3..-1.4 % there, but that came from switching off the startup parent probe (one copying minor, about 127 KB more copied on perft), not from the ladder. This PR does not change the probe.

Relation to #9949

#9949 (perf/tenuring-evidence-lock, open, not touched here) changes the survival-rate lock's latch: a startup window, a K=3 streak, and a sweep seed gated by startup.

Recorded, not fixed

The default survival-rate lock misfires on medium-lived records. medium2 W=5k/10k latch S=1, then the cohort dies in old-gen: 3 fulls and about 70..96 MB peak, against 33..57 MB at a pinned S=2 (-12 % instructions). This PR leaves that as it is (rows W=5k/10k). It is a lock question, and #9949's evidence window is the place for it.

Tests

The final head is 9d0ee47 (main merged).

  • cargo test -p perry-runtime --lib --release -- tenuring copying promot cohort nursery: 376 passed, 0 failed, 2 ignored.
  • GC schedule stress, instrumented runtime, final head. 2 098 parity programs from tests/parity/language: array, class, control-flow, function, generator, iterator, object, map, set, string, destructuring, spread, error, async, promise, json.
    • Each was compiled once with PERRY_GC_SCHEDULE_SEED=7.
    • Arms: default (ceiling 3) and MAX=4, at seed 7 (default rate and rate 1), plus the default arm with PERRY_GC_VERIFY_EVACUATION=1 at rate 1.
    • Result: 0 output or rc differences between the arms. The script flags 12 fixtures that fail to compile in this harness in both arms, 3 fixtures that print elapsed time, and 3 evacuation-verifier runs that time out at 60 s (default and MAX=4 equal at rate 1). 2 098 programs ran.
  • cargo check -p perry-runtime --lib --tests (Mac); scripts/check_gc_env_knobs.py OK.
  • scripts/check_gc_doc_claims.py: the only problem is one that is already on main (memory-model.md INT32_TAG).

Not run

Full suites, parity vs node, check-mode corpora (no facts change), S0, IR census, vf, tssrc, Supabase, the three.js skin bench, wall time, callgrind.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@proggeramlug
proggeramlug merged commit 6af7e75 into main Nov 14, 2026
91 of 92 checks passed
@proggeramlug
proggeramlug deleted the perf/gc-tenuring-cap branch November 14, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant