Repository navigation
bench: hole-purging chart under jemalloc, upstream mimalloc, Bun mimalloc and mimalloc-pprof (Performance section) - #334
Conversation
`ci/bench_hole_purging.py` can only answer "what does this tree's hole purging add
over its own scavenger", because no competitor allocator has a
`MIMALLOC_PURGE_HOLES` to switch off. This adds a sibling that runs the SAME churn
workload -- 150k x 512 B + 100k x 1 KiB + 50k x 2 KiB, a scattered 1-in-20 kept
alive, the rest freed, then a 10 s idle window -- once per allocator, and charts
resident set size over that window.
Five charted series: mimalloc-pprof, Bun's mimalloc and upstream mimalloc (each
linked against the static library `allocator-lock.json` builds, calling
`mi_on_thread_idle()` where the allocator's own header declares it), jemalloc in
its default configuration with nothing called, and the same jemalloc given an
explicit `mallctl("arena.<all>.purge")` on the same tick. Four uncharted
diagnostics answer the questions a reviewer asks first, and are reported in the
JSON and in the table below a rule.
Fairness is in the driver, not in the prose:
* nothing in the harness allocates. The block table is `mmap`ed, RSS is read with
`open`/`read`/`close` into a stack buffer, samples leave through `write(2)`.
`libmimalloc.a` overrides libc `malloc` and the `je_`-prefixed jemalloc build
does not, so a `printf` per idle tick would be allocator traffic in one arm and
not the other -- and allocator traffic during "idle" is exactly what jemalloc's
decay needs in order to fire;
* peak RSS is the kernel's `VmHWM`, not `max(sample)`: sampling starts at the top
of the idle window, so a sampled maximum would be post-free RSS;
* best of 3 runs by after-idle RSS, the same rule for every allocator, pinned with
`taskset -c 0-3`; every run's numbers go into the report JSON;
* `mi_on_thread_idle` support is read out of each allocator's extracted header
rather than assumed, so upstream's missing API is detected, not hardcoded;
* a diagnostic that tunes an allocator reads the setting back out of the allocator
and refuses to publish on a mismatch. This is not hypothetical: the first
`background_thread` row set `MALLOC_CONF`, which a `je_`-prefixed jemalloc
ignores in silence, and it produced a plausible, wrong 0%.
Source acquisition, checksums and build commands are reused from
`ci/build_benchmark_allocators.py` rather than re-implemented, so the pins are the
locked ones; `build_records` is deliberately not called, since it also cargo-builds
a `benchmark-child` per allocator that nothing here would run. tcmalloc is skipped
by name -- its locked build needs bazel.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
…locator run
The hole-purging chart lived under "Bun features", three screens away from the
other benchmarks, and it could only answer an in-tree A/B: this fork's scavenger
with hole purging off vs on. Both problems are fixed together.
New `## Performance` -> `### Memory returned after idle` subsection, last after the
existing benchmark subsections, carrying:
* the four-allocator chart and table produced by
`ci/bench_hole_purging_allocators.py` (measured at 37b77e2 on an AMD Ryzen 7
3700X, 6.18.48; every figure in the README and in both SVGs comes from that
run), and
* the existing off-vs-on pair, moved verbatim, under `#### Isolating this fork's
own contribution` -- it is still the only thing that separates hole purging
from everything else this fork does at an idle point.
"Bun features -> Hole purging, measured" keeps all of its prose and gains a
one-line pointer to the new home. Anchor updates follow it: the contents list, the
"hole punch" bullet in At a glance, the pointer under the scavenger API section,
and the feature table's row.
The numbers, and what they do and do not support:
| allocator | peak | after 10 s idle | returned |
|----------------------------------|-----------|-----------------|----------|
| mimalloc-pprof | 278.7 MB | 71.6 MB | 74% |
| Bun mimalloc | 278.6 MB | 71.7 MB | 74% |
| upstream mimalloc | 276.7 MB | 276.7 MB | 0% |
| jemalloc | 282.5 MB | 282.5 MB | 0% |
| jemalloc + explicit purge | 282.3 MB | 72.6 MB | 74% |
Three claims are made, and the third is a caveat on the first two. The 74% is
cooperative: with a survivor every 20 blocks essentially every 64 KiB mimalloc page
still holds something alive, so the background scavenger has no fully-free arena
memory to return on its own -- `mimalloc-pprof` with no idle hook returns 0%, and
all 74% of it is hole purging happening on the `mi_on_thread_idle()` call. jemalloc
in its default configuration returns nothing while idle, but reaches 74% with an
explicit `mallctl("arena.<all>.purge")` and 73% with its opt-in
`background_thread:true`, so the claim about jemalloc is stated narrowly: its
default configuration keeps sitting on this memory, not that it cannot give it
back. Upstream mimalloc is the hole-punch comparison -- no `mi_on_thread_idle` at
all, and 18% even when given `mi_collect(false)` on the same tick, independently
reproducing the 18% the off-vs-on chart measures for this fork with hole purging
disabled.
`docs/benchmarks.md`'s "Not covered by the five-allocator matrix" section said a
Bun series was possible but had been left for a run on the reference machine. That
is no longer true, so it is replaced by a full methodology section for both
scripts.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
…falsified Three corrections to the README written in 741f05f, none of which change a measured number. 1. The lead-in to the three bullets said "the third point is a caveat on the first two". It is the other way round after the bullets were rewritten: the first two are the caveats (the 74% is cooperative; jemalloc's 0% is a default-configuration number) and the third -- upstream mimalloc at 18% -- is the claim that survives them. 2. The Performance intro promised "Every result is GitHub-hosted and informational -- no self-hosted hardware, no hand-picked runs" and "Charts below are regenerated by the scheduled dashboard run", two screens above a subsection that is a dev box, a best-of-3, and committed SVGs. A trust sentence falsified further down the same page is worse than no trust sentence. Both now scope themselves to the throughput matrix and name the memory charts as the labelled exception. 3. The At-a-glance "hole punch" bullet compared 74% only against the scavenger alone. The competitor numbers now exist, so it carries them: 0% for upstream mimalloc, which has no `mi_on_thread_idle` at all, and 0% for jemalloc in its default configuration. Also records a check a reviewer would otherwise have to ask for: the upstream diagnostic uses `mi_collect(false)`, so the obvious objection is that upstream was handed the non-forcing collect and lost to `purge_delay`. Re-running the same driver against the same pinned upstream build with `mi_collect(true)` returns the identical 17.6% across three runs -- page granularity is the ceiling here, not the delay. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
|
Follow-up in 86e0c5a, no measured number changed:
And one check a reviewer would otherwise have to ask for. The upstream diagnostic uses |
…ifting Review of #334 found the README asserting a number with no committed row behind it, a caption that could go stale, and two gates that existed only in this branch's description. All of it is in the measurement layer. **A `mi_collect(true)` diagnostic (`upstream-mimalloc-collect-force`).** The README claims upstream returns the same 18% when the collect is *forced* -- the answer to "you gave upstream the non-forcing collect and it lost to its 1000 ms `purge_delay`". That was a side experiment, not a committed row, so the sentence had nothing behind it in the artifact set. It is now a `BENCH_IDLE_MI_COLLECT_FORCE` mechanism and a measured series, and it does return the same 17.6% across all three runs. **Run-to-run disagreement is computed, not narrated.** The charted figure is the best of 3, so a series that returned memory in only some of its runs would be represented by its lucky run alone -- which is exactly what `jemalloc, background_thread:true` did, returning in two runs of three. The table now renders an "only N of M runs" footnote for any such series, counted from the run records; the chart's caption carries the same count. Neither can go stale the way the hand-written version would have. (In this measurement every series is 3-of-3 and no footnote renders; a synthetic test covers the path.) **The caption states both jemalloc background windows.** jemalloc's default `dirty_decay_ms` is 10 s and the chart's window is 10 s, so that row sits exactly on the boundary and has been measured at both 0% and 73% in different sessions. Stating only whichever one this run produced would read as a verdict on jemalloc's decay thread that the data cannot support, so the caption always carries the 30 s figure and names the boundary. **A fifth caption line, and a real spread.** An SVG gets pasted into issues and slides without the README around it, so the cooperative caveat (`mimalloc-pprof` with no idle hook returns 0%; upstream given `mi_collect()` returns 18%) now travels on the image. The overlap annotation printed a hardcoded "within 1 MB" beside a 2 MB predicate; it computes the spread it actually measured. **VmHWM can read below the first VmRSS sample** -- both are maintained from per-CPU caches flushed periodically, and it did so in 13 of 27 runs. A "peak" under the first post-free sample is nonsense to a reader, so the peak is the larger of the two, and the table says both counters are good to a few hundred kB. **The repetition count is threaded through** instead of two hardcoded "3"s in the caption and the selection rule. **Both gates are wired up.** `ci/tests` compared only the light SVGs, and of the old script only its line chart -- a dark theme or a table that stopped reproducing passed silently. All eight committed SVGs (two scripts x chart/table x light/dark) are now compared. And nothing anywhere ran `--check`: it is now a step in `python-lint.yml` and a command in `ci/verify_local.py`'s lint config, for both scripts in both modes. Neither re-measures, so neither needs an allocator build. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
Assets regenerated from a full re-run at 86e0c5a (same machine, same rules), now including the `upstream-mimalloc-collect-force` diagnostic. Charted numbers are unchanged; every series is 3-of-3 with a spread of at most 0.1 MB. | series | peak | after idle | returned | |-------------------------------------|----------|------------|----------| | mimalloc-pprof | 278.7 MB | 71.6 MB | 74% | | jemalloc | 282.5 MB | 282.5 MB | 0% | | jemalloc + explicit purge | 282.4 MB | 72.6 MB | 74% | | Bun mimalloc | 278.7 MB | 71.7 MB | 74% | | upstream mimalloc | 276.7 MB | 276.7 MB | 0% | | mimalloc-pprof, no idle hook | 278.8 MB | 278.8 MB | 0% | | upstream mimalloc, mi_collect(false)| 276.6 MB | 227.8 MB | 18% | | upstream mimalloc, mi_collect(true) | 276.6 MB | 227.8 MB | 18% | | jemalloc, background_thread:true | 282.6 MB | 282.6 MB | 0% | | the same, 30 s window | 282.6 MB | 72.7 MB | 74% | Four prose corrections: * The `mi_collect(true)` sentence now cites a committed row rather than an unpublished side experiment, and says why the row exists. * jemalloc's `background_thread:true` figure is rewritten. It was reported as a flat 73%; the honest statement is that it lands on jemalloc's own boundary -- the default `dirty_decay_ms` is 10 s and the window is 10 s -- so the committed run returns 0% inside 10 s and 74% over 30 s, and an earlier session of the same benchmark returned in two runs of three at 10 s. The 30 s row is what settles it. * Neither chart pair is runner output: both are dev-box measurements, and the off-vs-on pair is median-of-3 while the cross-allocator pair is best-of-3. Said in both README and docs/benchmarks.md rather than left for a reader to infer from two subtitles. * The upstream row is `bcee5a88` (v3.4.3), not this fork's base, so upstream-vs-fork mixes base and fork changes -- the same caveat the throughput section already carries, now repeated where the 18% is claimed. The Bun row is the like-for-like line and lands on the same 74%. docs/benchmarks.md also now describes what is actually enforced (all eight SVGs re-rendered by `ci/tests`, plus `--check` in `python-lint.yml` and `ci/verify_local.py --only lint`) instead of only the test. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
|
Review addressed in 857bc43 ( B1 — B2 — the B3 — "not the reference machine". Correct, that was false: both pairs are the same dev box. The PR body now says both are dev-box measurements differing in selection rule (median-of-3 vs best-of-3), and the same statement is in the README (C7) and Should-fixes, all applied: C1 fifth+sixth caption lines so the cooperative caveat travels with the image; C2 at-a-glance now reads "18 % if you call One thing the review did not ask for but the C3 work exposed: the Performance intro promised "Every result is GitHub-hosted… no self-hosted hardware" two screens above a dev-box subsection. That is now scoped to the throughput matrix, with the memory charts named as the labelled exception. Green: 334 pytest, both scripts' |
The run-disagreement footnote is the one piece of table layout no committed asset exercises: every series in the committed measurement is 3-of-3, so the rendered table always has exactly one footnote line and the byte-for-byte asset comparisons can never see the two-line shape. An SVG has no layout engine, so a second footnote that collides with the first or falls past the viewBox renders silently wrong -- which is the failure mode review already caught once, in the "what runs during idle" column. The synthetic flaky-series test now parses its own output: exactly two 11px footnote lines, at least 12px apart, and the last one inside the viewBox height. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
The jemalloc `background_thread:true` bullet cited "two runs of three at 10 s" from an earlier session of the benchmark whose report JSON is not in this repository and never was. Every figure in the README has to come from the committed run; a number a reader cannot check in `.github/assets/allocator-idle-report.json` does not belong there, however true it is. Nothing is lost by removing it. The reason that row is borderline is structural and already stated: jemalloc's default `dirty_decay_ms` is 10 s and the window is 10 s, so the committed 0%-at-10-s / 74%-at-30-s pair is exactly what sitting on the boundary looks like. The cross-session history stays in the pull request description, where it is labelled as development history rather than as a measurement. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
|
Two more, pushed as 6db4920 (
|
Moves the hole-purging chart out of "Bun features" and into
## Performance, as thelast subsection after the existing benchmark subsections — and, while it was being
moved, gives it something to be compared against. Until now it could only answer an
in-tree A/B (
MIMALLOC_PURGE_HOLES=0vs=1in one binary), because no competitorallocator has that option to switch off.
The new
ci/bench_hole_purging_allocators.pyruns the same churn workload —150k × 512 B + 100k × 1 KiB + 50k × 2 KiB blocks, a scattered 1-in-20 kept alive,
the rest freed, then a 10 s idle window — once per allocator, each linked against the
static library
rust/benchmark-suite/allocators/allocator-lock.jsonbuilds.Measured
AMD Ryzen 7 3700X (16 threads), Linux 6.18.48,
taskset -c 0-3, at commit86e0c5a4on this branch. Best of 3 runs by after-idle RSS, the same rule for everyallocator. Peak is the kernel's
VmHWM.mi_on_thread_idle()every 100 msmallctl("arena.<all>.purge")every 100 msmi_on_thread_idle()every 100 msDiagnostics — measured, recorded in the report JSON, shown below a rule in the table
SVG, never charted:
mi_collect(false)mi_collect(false)every 100 msmi_collect(true)mi_collect(true)every 100 msbackground_thread:trueJE_MALLOC_CONF=background_thread:truebackground_thread:true, 30 sEvery series in the committed run is 3-of-3 with a run-to-run spread of at most
0.1 MB; all three runs of each are in
.github/assets/allocator-idle-report.json.The one row that is genuinely borderline is jemalloc's
background_thread:trueat10 s — see below.
What this does and does not support
The finding that was not anticipated, first:
mimalloc-pprofwith no idle hookreturns 0 %. On this workload a survivor lands every 20 blocks, so essentially
every 64 KiB mimalloc page still holds something alive and there is no fully-free
arena memory for the background scavenger to return by itself. The entire 74 % is
hole purging, and it happens on the
mi_on_thread_idle()call an embedder makesbefore it blocks. The README says so in the same breath as the 74 %, the chart SVG
carries it in its own caption, and a bridging sentence was added to the "Bun
features" prose (which says an idle process "stops sitting on memory it no longer
needs") so the two cannot be read as contradicting.
jemalloc: the owner's phrasing holds — jemalloc can return memory if you ask; it
doesn't after idle — but only for the default configuration, and the PR/README say
exactly that. Its decay is advanced by allocation activity, not by time spent idle,
so the default line is flat; an explicit
mallctl("arena.<all>.purge")gets 74 %.Its opt-in
background_thread:truesits exactly on jemalloc's own boundary: thedefault
dirty_decay_msis 10 s and this window is 10 s, so the committed runreturns 0 % inside 10 s and 74 % over 30 s — and an earlier session of the same
benchmark had that row returning in two runs of three at 10 s. Both windows are on
the chart caption and in the diagnostics for that reason. Not claimed anywhere: that
jemalloc's mechanism is worse — the cost of either hook was not measured.
upstream mimalloc is the hole-punch comparison, and it is the strongest honest
sentence here: no
mi_on_thread_idleat all, and 18 % when givenmi_collect(false)on the same tick — and the same 18 % when givenmi_collect(true), which forces the purge rather than honouring upstream's 1000 mspurge_delay. That is a committed diagnostic row precisely so the obvious objection("you gave it the non-forcing collect") has an answer in the artifact set rather than
in a comment. Page granularity is the ceiling, not the delay. It also independently
reproduces the 18 % the off-vs-on chart measures for this fork's own scavenger with
hole purging disabled. Whole-page return gets 18 %; punching holes in still-used
pages gets 74 %. Caveat repeated where the number is claimed: the upstream row is
bcee5a88(v3.4.3) and not this fork's base, so upstream-vs-fork mixes base and forkchanges; Bun's row is the like-for-like line and lands on the same 74 %.
Not measured, offered only as an explanation: jemalloc's per-size-class slabs are
much smaller than mimalloc's 64 KiB pages, so a 1-in-20 survivor rate leaves many
jemalloc slabs completely free and a forced purge can return them without needing
anything hole-shaped. That is a structural difference, not something this benchmark
established.
Method, and the fairness rules that are in the driver rather than the prose
mmaped, RSS is read withopen/read/closeinto a stack buffer, samples leave throughwrite(2).libmimalloc.acarriesalloc-override.c, so in the three mimalloc children everylibc
mallocin the process is mimalloc's, while in theje_-prefixed jemallocchildren it is glibc's — a
printfper idle tick would be allocator traffic in onearm and not the other, and allocator traffic during "idle" is exactly what
jemalloc's decay needs in order to fire.
VmHWM, read at the end, floored at the first sample. Sampling startsat the top of the idle window, so
max(sample)would be post-free RSS; and bothcounters come from per-CPU caches flushed periodically, so
VmHWMcan read belowa
VmRSSsample taken moments earlier (it did in 13 of 27 runs). Both are good toa few hundred kB, which the table says.
mi_on_thread_idlesupport is read out of each allocator's extracted header,not assumed — upstream at its pin has none, which the script detects.
reads the setting back out of it and refuses to publish on a mismatch. This caught
a real bug mid-development: the first
background_threadrow setMALLOC_CONF,which a
je_-prefixed jemalloc ignores in complete silence (it readsJE_MALLOC_CONF), and it produced a perfectly plausible 0 % that would haveshipped as "even jemalloc's decay thread returns nothing".
ci/testshas theRED/GREEN for it.
the best of 3, so a series that returned memory in only some of its runs would be
represented by its lucky run alone. The table renders an "only N of M runs"
footnote for any such series, counted from the run records, and the chart caption
carries the same count — so it cannot go stale on the next measurement.
ci/build_benchmark_allocators.py, so the pins are the locked ones.build_recordsis deliberately not called — it also cargo-builds abenchmark-childper allocator that nothing here would run.Caveats
measuring machine did not have; a substitute build would not be the pinned one.
Named in the chart's prose, in
docs/benchmarks.md, and in the report JSON'sskipped_allocators.in both cases, but two separate runs with different selection rules (median of 3
for the off-vs-on pair, best of 3 for the cross-allocator pair). Each SVG names its
own machine, kernel, commit and rule; the README and
docs/benchmarks.mdsay it inwords as well, and the Performance intro's "GitHub-hosted, no self-hosted hardware"
promise is now scoped to the throughput matrix so the page does not falsify itself
two screens later. The off-vs-on pair is committed unchanged.
SSL_CERT_FILEpointed at the system CAbundle in this sandbox. That is an environment quirk, not a script change.
Placement and anchors
### Memory returned after idleis the last subsection of## Performanceand holdsboth chart pairs — the four-allocator one, then the moved off-vs-on pair under
#### Isolating this fork's own contribution. "Bun features → Hole purging,measured" keeps every word of its prose and gains a one-line pointer. Anchor updates:
the contents list, the At-a-glance "hole punch" bullet, the pointer under the
scavenger API section, and the feature table row.
docs/benchmarks.md's "Not coveredby the five-allocator matrix" section claimed a Bun series was possible but had been
left for a run on the reference machine — this PR makes that false, so it is replaced
with a full methodology section for both scripts.
Verification
ci/tests(334 tests) green, includingtest_bench_hole_purging_allocators.py,which re-renders all eight committed SVGs (two scripts × chart/table ×
light/dark) from the committed CSV/JSON and fails on any difference, asserts the
README
alttext is the same sentence the SVG carries, guards the table's columnwidths (an SVG has no layout engine — the
background_threadrows overflowed intothe peak column once already, and only a rendered PNG showed it), and covers the
run-disagreement footnote synthetically since the committed run is 3-of-3
everywhere.
--checkfor both scripts in both modes is now a step inpython-lint.ymland a command inci/verify_local.py's lint config; neitherre-measures. Also green:
ci/check_doc_snippets.py, ruff 0.12.10 + pyright 1.1.411strict, and
ci/verify_local.py --only lint.Every figure in the charts, the table SVGs and the README comes from the run
described above.
Was stacked on #330 during development; #330 has since merged, so this is rebased
onto
mainand targetsmaindirectly.🤖 Generated with Claude Code
https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S