Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/results/collect-capacity-v1-kernels.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load median 3.56 max 4.27
records base wall med 1.699s cycles med 7.195G
cap /base wall 1.0072 (0.9869-1.0165) cycles 1.0066 (0.9891-1.0193) instr 1.0000 (0.9999-1.0002) rss 1.0000 (1.0000-1.0000)
collections base wall med 2.074s cycles med 8.801G
cap /base wall 1.0232 (1.0173-1.0367) cycles 1.0226 (1.0214-1.0276) instr 0.9962 (0.9961-0.9963) rss 0.9974 (0.9955-1.0015)
strings base wall med 0.840s cycles med 3.535G
cap /base wall 0.9973 (0.9911-1.0209) cycles 0.9961 (0.9873-1.0211) instr 0.9940 (0.9939-0.9942) rss 1.0021 (0.9992-1.0042)
serialization base wall med 1.082s cycles med 4.646G
cap /base wall 0.9837 (0.9630-1.0011) cycles 0.9807 (0.9703-0.9953) instr 0.9879 (0.9877-0.9880) rss 1.0000 (0.9991-1.0024)
pipelines base wall med 1.119s cycles med 4.74G
cap /base wall 0.9920 (0.9789-1.0118) cycles 0.9924 (0.9828-1.0015) instr 0.9955 (0.9954-0.9956) rss 1.0000 (1.0000-1.0000)
closures base wall med 0.248s cycles med 1.049G
cap /base wall 0.9894 (0.9814-1.0169) cycles 0.9839 (0.9793-1.0032) instr 0.9907 (0.9902-0.9910) rss 1.0009 (1.0004-1.0031)
30 changes: 30 additions & 0 deletions docs/results/collect-capacity-v1-v7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
main-base 71.47 s 325233943208 cycles 1621989852566 instructions 2227814400 RSS
main-cap 68.45 s 322785339929 cycles 1615624832823 instructions 2226503680 RSS
main-base 66.59 s 318223495362 cycles 1621751918495 instructions 2226814976 RSS
main-cap 66.19 s 316444984438 cycles 1615281284475 instructions 2226913280 RSS
main-base 70.71 s 328220051345 cycles 1622243089211 instructions 2227683328 RSS
main-cap 70.64 s 328361524448 cycles 1615970883309 instructions 2227224576 RSS
main-base 66.33 s 318481917705 cycles 1621693994841 instructions 2227044352 RSS
main-cap 85.46 s 325425159431 cycles 1615136478203 instructions 2226864128 RSS
main-base 64.82 s 313506646407 cycles 1620970673476 instructions 2225815552 RSS
main-cap 83.14 s 325668714523 cycles 1614524190707 instructions 2226962432 RSS
main-base 64.65 s 312072583504 cycles 1620670394576 instructions 2226896896 RSS
main-cap 63.75 s 309209382263 cycles 1614274788064 instructions 2226880512 RSS
main-base 64.90 s 314375135738 cycles 1621460348766 instructions 2227683328 RSS
main-cap 66.19 s 317261019750 cycles 1615281494965 instructions 2226831360 RSS
main-base 70.59 s 329570311063 cycles 1622445629540 instructions 2227929088 RSS
main-cap 68.08 s 324169460937 cycles 1615972882605 instructions 2227273728 RSS
main-base 71.19 s 329223812998 cycles 1622337384097 instructions 2227388416 RSS
main-cap 68.58 s 323990977062 cycles 1615484394897 instructions 2226946048 RSS
main-base 72.29 s 330798277870 cycles 1622184939726 instructions 2225274880 RSS
main-cap 69.12 s 325637306910 cycles 1615670155788 instructions 2227585024 RSS
main-base 67.22 s 323698354115 cycles 1622045548627 instructions 2227650560 RSS
main-cap 67.11 s 319371897369 cycles 1615538828005 instructions 2227650560 RSS
main-base 66.81 s 319857886128 cycles 1621810305253 instructions 2226798592 RSS
main-cap 69.38 s 326984155798 cycles 1615936273743 instructions 2226536448 RSS
main-base 70.33 s 331662081195 cycles 1622558330324 instructions 2226339840 RSS
main-cap 69.06 s 326772509531 cycles 1615697598932 instructions 2226274304 RSS
main-base 85.70 s 343110350304 cycles 1622351019540 instructions 2227699712 RSS
main-cap 67.27 s 320122370665 cycles 1615562179735 instructions 2226896896 RSS
main-base 86.33 s 342385642619 cycles 1622579963061 instructions 2227142656 RSS
main-cap 74.60 s 333534956525 cycles 1616711911368 instructions 2225782784 RSS
112 changes: 112 additions & 0 deletions docs/results/collect-capacity-v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Collection costs off empty capacity

24 November 2026, macOS arm64 (M5 Max). The fix is `7fb69dd25` on main
`183ec7044`, with `ceead4773` adapting `verify-heap-tools` to it. The
investigation looked for the fixed cost of a generational collection: work
that scales with heap capacity rather than with live data.

## Breakdown

A scratch timing patch
([worker-runtime-collection-costs-v1-timing.patch](worker-runtime-collection-costs-v1-timing.patch))
timed each collection phase with the host clock. It is not part of any image.
The program churned 4, 32 and 256 MiB nurseries with serial and parallel
marking, holding 256 small arrays live, then forced a major collection with
the nursery half full and another with it empty. The records are in
[worker-runtime-collection-costs-v1-phases.txt](worker-runtime-collection-costs-v1-phases.txt).
They were measured on the Worker stream's branch (`5e489f8f0`), whose
collector code is the same as main's.

Two costs scaled with capacity:

- **Forced major, nursery not empty.** The compactor covered the whole span
up to old capacity plus the young top, including the untouched gap above
the old fill. Its live-bit clear, offset pass, forwarding and packing ran
over every bitmap word: 4.0 M words at 256 MiB, against 129 words for the
same live data with the nursery empty. With 32 KB live, it took 43 ms at
256 MiB (parallel marking) and 4.9 ms at 32 MiB.
- **Bitmap clears.** The nursery's start bits (every minor collection), the
compactor's live bits and the dirty table were cleared with `fill`, which
stores element by element. The nursery clear took about 20 µs per minor
collection at 4 MiB, 155 µs at 32 MiB and 1.3 ms at 256 MiB.

Everything else per collection was small and did not scale with capacity.
Holding and releasing the collector and clearing the remembered set took at
most a few microseconds each, after a one-time hold of about 0.1 ms at the
first collection.

## Fix

- A major collection while the nursery holds objects first evacuates the
nursery (an ordinary minor collection), then compacts only the packed old
prefix. A nursery whose survivors cannot fit the old prefix still compacts
in place. The pages released afterwards are the same.
- Bitmap clears use `set` from a permanent zero block, one copy per 2 KiB.
Typed `fill` codegen is a separate item for the codegen stream.

## Results

**Forced majors** (scratch probe, 15 repetitions: 3 runs of 5; records in
[worker-runtime-collection-costs-v1-e2e.txt](worker-runtime-collection-costs-v1-e2e.txt)),
median ms:

| Nursery | Major, nursery half full | Major, nursery empty | 12 nurseries of minor churn |
| ------- | ------------------------ | -------------------- | --------------------------- |
| 4 MiB | 0.63 → 0.16 (−75%) | 0.069 → 0.061 | 16.6 → 16.7 (+0.3%) |
| 32 MiB | 4.05 → 0.50 (−88%) | 0.072 → 0.063 | 131.2 → 126.8 (−3.3%) |
| 256 MiB | 31.5 → 2.35 (−93%) | 0.075 → 0.067 | 1062 → 1037 (−2.4%) |

**Frozen v7** (`--runtime-tree` images of main `183ec7044` and of the fix,
15 paired rounds, base first in each; load median 4.6, max 13.6; runs in
[collect-capacity-v1-v7.txt](collect-capacity-v1-v7.txt)): neutral to
slightly better.

| Metric | Base median | Fix median | Paired fix/base: median (quartiles) | Fix lower in |
| ------------ | ----------- | ---------- | ----------------------------------- | ------------ |
| Cycles | 325.2 G | 324.2 G | 0.9908 (0.9841–1.0092) | 10/15 |
| Wall | 70.33 s | 68.58 s | 0.9861 (0.9577–1.0199) | 11/15 |
| Instructions | 1622.0 G | 1616.0 G | 0.9960 (0.9960–0.9961) | 15/15 |
| Peak RSS | 2.227 GB | 2.227 GB | 0.9999 | 11/15 |

**Allocating feature kernels** (native images of main `183ec7044` and of
the fix, 15 rounds with the order rotating; load median 3.6, max 4.3; via
`/usr/bin/time -l`; results in
[collect-capacity-v1-kernels.txt](collect-capacity-v1-kernels.txt)).
Ratios are fix/base per round: median (quartiles).

| Kernel | Base cycles | Cycles | Wall | Instructions |
| ------------- | ----------- | ---------------------- | ---------------------- | ------------ |
| records | 7.20 G | 1.0066 (0.9891–1.0193) | 1.0072 (0.9869–1.0165) | 1.0000 |
| collections | 8.80 G | 1.0226 (1.0214–1.0276) | 1.0232 (1.0173–1.0367) | 0.9962 |
| strings | 3.54 G | 0.9961 (0.9873–1.0211) | 0.9973 (0.9911–1.0209) | 0.9940 |
| serialization | 4.65 G | 0.9807 (0.9703–0.9953) | 0.9837 (0.9630–1.0011) | 0.9879 |
| pipelines | 4.74 G | 0.9924 (0.9828–1.0015) | 0.9920 (0.9789–1.0118) | 0.9955 |
| closures | 1.05 G | 0.9839 (0.9793–1.0032) | 0.9894 (0.9814–1.0169) | 0.9907 |

**Collections: +2.3% cycles, not in the collector.** The kernel keeps
almost nothing live in a 32 MiB nursery, so it runs only minor collections.
The only fix it reaches is the faster nursery clear, and it retires 0.4%
fewer instructions. pprofessor profiles of debug-symbol builds (5 runs each,
999 Hz, all threads) put the allocator and collector at a median 15 ms per
run on main and 8 ms with the fix, about 1% of the 1.5 s main thread. The
extra cycles are in mutator code (map and set operations) that the fix does
not change. The measured image's text is exactly one page (4096 bytes)
larger, and in the debug-symbol builds the program's functions moved by
exactly 4096 bytes: each keeps its in-page alignment but not its page. The regression is consistent with a page-level placement
effect (instruction cache or branch predictor aliasing), not proven. The
stacked start-bitmap PR measures collections at 0.968 of this fix, about
1% below main.

**Gates on main** (fix `7fb69dd25`, tools `ceead4773`):

- Collector native fixtures, 16/16, under LLDB: compaction (small and large
heaps), granules, released semispaces, stack maps, weak cells on the
copying collector, the generational collector and its parallel paths,
safe-for-space and block forwarding.
- `verify-heap-tools`: passes after `ceead4773`. The collector has no
`if (minor)` line any more, and inside `collect` the young and old tops die
at the evacuation call, so LLDB cannot read them there. The tool now breaks
in `evacuateNursery` after its first call, where both are homed and nothing
has moved yet.
- Native compiler subset check; Node-built stage 1, then native stages 2
and 3: stage2 == stage3.
111 changes: 111 additions & 0 deletions docs/results/worker-runtime-collection-costs-v1-e2e.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
Program-level timings (scratch probe, 15 repetitions each: 3 runs x 5): churn = 12 nurseries of
short-lived allocation with 256 live arrays; then a forced major with the nursery half full, then one
with it empty. base = 5e489f8f0, new = 29cbe418b.
== base-256-1
E2E churn 1024.6192500591278 majorFull 35.26316595077515 majorEmpty 0.08500003814697266
E2E churn 1027.7944161891937 majorFull 31.473000049591064 majorEmpty 0.10108304023742676
E2E churn 1009.0022501945496 majorFull 30.111250162124634 majorEmpty 0.07474994659423828
E2E churn 1007.4452500343323 majorFull 31.139874935150146 majorEmpty 0.08470797538757324
E2E churn 998.1640000343323 majorFull 31.5853750705719 majorEmpty 0.07154083251953125
== base-256-2
E2E churn 1068.8254170417786 majorFull 35.673750162124634 majorEmpty 0.08691596984863281
E2E churn 1061.665209054947 majorFull 30.54183292388916 majorEmpty 0.07208418846130371
E2E churn 1070.5081250667572 majorFull 32.46141719818115 majorEmpty 0.08424997329711914
E2E churn 1056.564374923706 majorFull 32.08633303642273 majorEmpty 0.10220909118652344
E2E churn 1058.7056670188904 majorFull 31.38824987411499 majorEmpty 0.07129216194152832
== base-256-3
E2E churn 1082.8625419139862 majorFull 34.66204214096069 majorEmpty 0.08487486839294434
E2E churn 1072.4947090148926 majorFull 31.650458097457886 majorEmpty 0.07450008392333984
E2E churn 1066.7251670360565 majorFull 30.4858341217041 majorEmpty 0.07420802116394043
E2E churn 1068.3137090206146 majorFull 30.176292181015015 majorEmpty 0.07004094123840332
E2E churn 1074.4403331279755 majorFull 31.02466607093811 majorEmpty 0.07145905494689941
== base-32-1
E2E churn 134.03366708755493 majorFull 4.416583061218262 majorEmpty 0.0747079849243164
E2E churn 130.81637501716614 majorFull 4.020792007446289 majorEmpty 0.06941604614257812
E2E churn 132.85237503051758 majorFull 4.364042043685913 majorEmpty 0.07629108428955078
E2E churn 131.7294580936432 majorFull 4.050374984741211 majorEmpty 0.07233309745788574
E2E churn 130.9603750705719 majorFull 3.883542060852051 majorEmpty 0.07262492179870605
== base-32-2
E2E churn 134.00999999046326 majorFull 4.337291955947876 majorEmpty 0.07350015640258789
E2E churn 131.09108304977417 majorFull 4.126166105270386 majorEmpty 0.06883406639099121
E2E churn 128.92891693115234 majorFull 3.8962080478668213 majorEmpty 0.0696249008178711
E2E churn 133.8891670703888 majorFull 4.078290939331055 majorEmpty 0.06587505340576172
E2E churn 131.88062500953674 majorFull 3.851541042327881 majorEmpty 0.07158398628234863
== base-32-3
E2E churn 134.86504101753235 majorFull 5.196749925613403 majorEmpty 0.0779581069946289
E2E churn 131.15574979782104 majorFull 3.977250099182129 majorEmpty 0.07120800018310547
E2E churn 131.08087491989136 majorFull 4.132499933242798 majorEmpty 0.06829118728637695
E2E churn 129.88679194450378 majorFull 4.040374994277954 majorEmpty 0.07404208183288574
E2E churn 129.58025002479553 majorFull 4.031875133514404 majorEmpty 0.0728750228881836
== base-4-1
E2E churn 17.691582918167114 majorFull 0.8263750076293945 majorEmpty 0.07004189491271973
E2E churn 16.24524998664856 majorFull 0.6299169063568115 majorEmpty 0.06399989128112793
E2E churn 15.735167026519775 majorFull 0.617833137512207 majorEmpty 0.07195782661437988
E2E churn 15.846082925796509 majorFull 0.6620829105377197 majorEmpty 0.06587505340576172
E2E churn 15.733375072479248 majorFull 0.6607089042663574 majorEmpty 0.06808304786682129
== base-4-2
E2E churn 17.00012516975403 majorFull 0.679542064666748 majorEmpty 0.07112503051757812
E2E churn 16.61074995994568 majorFull 0.5891249179840088 majorEmpty 0.06904220581054688
E2E churn 15.722500085830688 majorFull 0.6162078380584717 majorEmpty 0.0672919750213623
E2E churn 15.692749977111816 majorFull 0.6085829734802246 majorEmpty 0.06858301162719727
E2E churn 16.214416980743408 majorFull 0.628291130065918 majorEmpty 0.06749987602233887
== base-4-3
E2E churn 16.963000059127808 majorFull 0.678333044052124 majorEmpty 0.08379197120666504
E2E churn 17.018208980560303 majorFull 0.6832499504089355 majorEmpty 0.0748751163482666
E2E churn 17.826541900634766 majorFull 0.656041145324707 majorEmpty 0.06712484359741211
E2E churn 16.729333877563477 majorFull 0.6205830574035645 majorEmpty 0.06891703605651855
E2E churn 16.636374950408936 majorFull 0.6031248569488525 majorEmpty 0.06766700744628906
== new-256-1
E2E churn 1044.8307919502258 majorFull 2.464207887649536 majorEmpty 0.07566690444946289
E2E churn 1036.5117919445038 majorFull 2.3963329792022705 majorEmpty 0.07212495803833008
E2E churn 1014.0035829544067 majorFull 2.1167080402374268 majorEmpty 0.0779578685760498
E2E churn 975.2532908916473 majorFull 2.2715840339660645 majorEmpty 0.06308293342590332
E2E churn 984.6681251525879 majorFull 2.350749969482422 majorEmpty 0.07129192352294922
== new-256-2
E2E churn 1058.6283328533173 majorFull 2.244874954223633 majorEmpty 0.0787498950958252
E2E churn 1064.7582919597626 majorFull 3.9417920112609863 majorEmpty 0.06462502479553223
E2E churn 1090.7399580478668 majorFull 2.355333089828491 majorEmpty 0.07024979591369629
E2E churn 1062.2755000591278 majorFull 2.2355000972747803 majorEmpty 0.0634160041809082
E2E churn 1070.3177089691162 majorFull 2.3962080478668213 majorEmpty 0.06133389472961426
== new-256-3
E2E churn 1012.9264998435974 majorFull 2.1137919425964355 majorEmpty 0.06541705131530762
E2E churn 1032.6995000839233 majorFull 2.4395840167999268 majorEmpty 0.06541585922241211
E2E churn 1020.6865410804749 majorFull 2.307708978652954 majorEmpty 0.06725001335144043
E2E churn 1012.7030000686646 majorFull 2.2821249961853027 majorEmpty 0.06641697883605957
E2E churn 1081.551207780838 majorFull 2.777333974838257 majorEmpty 0.07754111289978027
== new-32-1
E2E churn 129.42283391952515 majorFull 0.2992079257965088 majorEmpty 0.06037497520446777
E2E churn 131.33487510681152 majorFull 0.6031668186187744 majorEmpty 0.061875104904174805
E2E churn 127.97525000572205 majorFull 0.493333101272583 majorEmpty 0.06120896339416504
E2E churn 131.94787502288818 majorFull 0.32700014114379883 majorEmpty 0.06420779228210449
E2E churn 131.55495810508728 majorFull 0.5009589195251465 majorEmpty 0.0603330135345459
== new-32-2
E2E churn 125.0002920627594 majorFull 0.32866716384887695 majorEmpty 0.0717918872833252
E2E churn 123.98624992370605 majorFull 0.5138339996337891 majorEmpty 0.06291604042053223
E2E churn 120.86558318138123 majorFull 0.5193328857421875 majorEmpty 0.061167001724243164
E2E churn 126.39945793151855 majorFull 0.6007080078125 majorEmpty 0.06287503242492676
E2E churn 120.97262501716614 majorFull 0.30808281898498535 majorEmpty 0.0696251392364502
== new-32-3
E2E churn 129.10524988174438 majorFull 0.32000017166137695 majorEmpty 0.06329083442687988
E2E churn 126.8203752040863 majorFull 0.5315840244293213 majorEmpty 0.06104087829589844
E2E churn 124.1677918434143 majorFull 0.3041248321533203 majorEmpty 0.06533408164978027
E2E churn 127.94941687583923 majorFull 0.519291877746582 majorEmpty 0.060791969299316406
E2E churn 124.77966690063477 majorFull 0.7738749980926514 majorEmpty 0.06379103660583496
== new-4-1
E2E churn 17.162999868392944 majorFull 0.15108299255371094 majorEmpty 0.060500144958496094
E2E churn 16.47191596031189 majorFull 0.17133402824401855 majorEmpty 0.06137490272521973
E2E churn 16.375499963760376 majorFull 0.13579201698303223 majorEmpty 0.06049990653991699
E2E churn 16.392791986465454 majorFull 0.15854096412658691 majorEmpty 0.06054210662841797
E2E churn 16.483749866485596 majorFull 0.15862512588500977 majorEmpty 0.06262493133544922
== new-4-2
E2E churn 16.6788330078125 majorFull 0.15204215049743652 majorEmpty 0.060957908630371094
E2E churn 16.350375175476074 majorFull 0.16199994087219238 majorEmpty 0.06412506103515625
E2E churn 16.676125049591064 majorFull 0.3078329563140869 majorEmpty 0.0782918930053711
E2E churn 16.669041872024536 majorFull 0.15124988555908203 majorEmpty 0.060916900634765625
E2E churn 16.52970814704895 majorFull 0.21083307266235352 majorEmpty 0.06120800971984863
== new-4-3
E2E churn 16.776583909988403 majorFull 0.1502079963684082 majorEmpty 0.06099987030029297
E2E churn 16.822041988372803 majorFull 0.16558289527893066 majorEmpty 0.06304216384887695
E2E churn 16.72079110145569 majorFull 0.1657090187072754 majorEmpty 0.060957908630371094
E2E churn 16.66716694831848 majorFull 0.16962504386901855 majorEmpty 0.0614168643951416
E2E churn 16.254791975021362 majorFull 0.15366601943969727 majorEmpty 0.06124997138977051
Loading
Loading