Repository navigation
Re-pin bench, run on R 3.x, add the perf category classifier - #3
Open
MatejKocourek wants to merge 1 commit into
Open
MatejKocourek wants to merge 1 commit into
MatejKocourek wants to merge 1 commit into
Conversation
- Re-pin PRL-PRG/bench to 4639a83 (main); the old pin 7bc2cbb is no longer on any bench branch. Adapt rbench.py and rbench_perf.py to the new bench API, keeping the CSV schema and the --numa, --csv-merge and --show options. - Make the harness R 3.x-safe: --slave instead of --no-echo, gc() instead of gc(full = TRUE). - Add profile/perf-rules.R (VMIL26 classifier, byte-identical, MIT with its author's agreement) and profile/categorize.R, which turns rbench_perf.py recordings into per-category shares. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
This prepares r-benchmarks to be the benchmark layer of the r-speed dashboard
(ISC grant), which tracks R's speed across releases back to 3.0.0 and R-devel.
Three things blocked that:
PRL-PRG/benchat7bc2cbb, which no bench branch contains any more (bench's history wasrewritten). GitHub still serves it, but it can be garbage-collected at any
time, and then
uv run --script rbench.pystops resolving.--no-echo), and the harnesscalled
gc(full = TRUE), an argument R only has from 3.5.0.rbench_perf.pyrecordsperfand the instrument harness printsMARKlines, but the classifier that maps frames to categories lives only in the
VMIL26 paper artifact.
What changed
bench re-pinned to
4639a83(benchmain), drivers adaptedbench's API changed a lot between the two commits (2026-09/10 refactor). The
drivers were adapted to it without changing what they measure:
@dataclass(frozen=True) class Params(SharedBenchParams)bench.Paramsmakes every subclass a frozen kw-only dataclass, and decorating it again is aTypeErrorRegex(...)+.with_harness(monitor=_iteration_monitor)framing a streaming harnessRegexMetric(..., stdout_metric_source, iterate=True)over the finished stdout; the n-th match is iteration n (bench no longer streams harnesses).with_warmup(FixedRuns(warmups))/.with_runs(FixedRuns(iterations))counting iterations.with_warmup(0).with_runs(1)plus a smallInProcessWarmupcontroller that flags the firstwarmupsiterations of each processelapsedsample,.with_process_metric(max_rss()).with_metric(..., Time(), max_rss())(Metric and ProcessMetric merged)harness_success, a success function that adds it back.with_environment(SystemEnvironment())+.with_diagnostics(...).with_probe(SystemProbe() & ProfileProbe()); bench has no driver-diagnostics hook any more, soRBENCH_PROFILEis recorded in the fingerprint (JSON and the CSV preamble) and said once on stderrSummaryReporter(Results() & Summary() & GeomeanSummary(axis, metrics="runtime"))passed intodefault_reporter.with_summary(ByBenchmarkMetricSummary() & ComparisonSummary() & GeomeanComparisonSummary(axis=...).on_metrics("runtime"))default_reporter(ctx, ...)default_reporter(params, ...).add_all(*SUITES),.with_label(lambda b: f"run{b.run}").add(*SUITES),b.variant['run']PerfRecord(...)as a process metric without_dirPerfRecord(root, ...)as a controller (.with_controller); it writes into the sameexecution_dirthe dir reporter uses--numa,--csv-mergefrom benchrbench.Params(numactl prefix in_r_cmd; merge in the driver's CSV reporter)--show FILEshow FILEsubcommand;rb.main()rewrites--show FILEto itoutliercolumn that only appears when an outlier is flagged.RbenchCsvReporterwrites the old schema exactly, so downstream readers (CI's failure check, r-speed) are unaffectedrbench_perf.pynow passesoverride=Truewhere it replaces abase_appsetting, because bench warns otherwise. It also drops the geomean block from its summary, since there is no
runtimemetric to rank.R 3.x
R --no-echo→R --slavein_r_cmd(and in the READMEs). R 4.0 renamedthe flag but still accepts
--slavesilently (checked on 4.6.1: same output,nothing on stderr, exit 0), and it is the only spelling 3.x knows. I chose
this over picking the flag from
R --version: that would mean a subprocessat plan time (also for
--list/--dry), and R-devel's--versionprints noversion number to parse.
gc(full = TRUE)→gc()in both harnesses.fullwas added in R 3.5.0(checked in R's SVN
gc.Rdat R-3-4-0 vs R-3-5-0), where it defaults toTRUE. Before that,do_gcalways collected every generation (R-3-4-0memory.c). The call does the same thing on every version.harness.R/harness_instrument.Ris newer than 3.0: no\(x),|>, raw strings,trimws,startsWith,isFALSE,...length.marker.cuses onlyRf_ScalarReal.profile/: the category classifierprofile/perf-rules.R: VMIL26analysis/perf-rules.Rat8b42516,byte-identical (sha256
e1168de6…). Provenance is inprofile/ORIGIN.md.profile/categorize.R: applies it the way VMIL26'scategories.Rmddoes(
read_perf_frames→add_marked_region(read_perf_marks(stdout))→classify_frames(rules)→sample_regions→ keepregion == "execute"). Itreads an
rbench_perf.py --dirtree and writes one row per (recording,category):
suite, benchmark, variant, run, category, samples, kernel_samples, share, share_classified.shareincludesunattributed, sothe categories and
unattributedsum to 1.share_classifiedis VMIL26'sper-run
pct/100, which excludes it.--causes FILEwrites the top Nunclassified_causes()per recording. A recording with noMARK executeorno kernel samples is skipped with a warning.
README
The harness command line uses
--slave, with a note on why. The profilingsection covers
categorize.R. The driver example drops@dataclassandmentions
override=True,rb.main, and the licence note forprofile/.How it was tested
On system R 4.6.1 (Gentoo, laptop, noisy: the numbers are not comparable, only
the shapes are):
uv run --script rbench.py --list: 590 variants. Output is identical tothe old pin.
rbench.py --include '^areWeFast/(bounce|mandelbrot)/run0' --runs 1 --iterations 2 --warmups 1 --csv --json --dir, old pin vs new: CSV headeridentical
(
suite,benchmark,run,run,iteration,warmup,metric,value,unit,lower_is_better,outlier,failure).Row shape identical: every non-value column of every row matches.
one is fine), old vs new: identical, except that the new reporter also writes
the mid-run failure. The old pin lost it silently, so CI's failure check
could not see it.
--csv-mergecarries over unmeasured benchmarks and writes the# merged:note.
--show FILErenders a saved report.--dry --numa 0shows thenumactlprefix and--slave.--iterations 0fails with "no iterationsparsed from harness output", as before.
areWeFast/bounce,areWeFast/mandelbrotandshootout/nbody/nbodyafter the harnessgc()change.rbench_perf.py --helpimports cleanly. No realperfrecording:perfis not installed on the test machine. The plumbing was tested end to end
with a stand-in
perfonPATH:recordruns the command, andscriptemits synthetic stacks timed inside the real
MARKwindows frommarker.so. The output tree,perf-frames.csv,stdoutwithMARKlinesand the CSV all came out as expected.
categorize.Ron those synthetic recordings: the shares are exactly theconstructed ones (mem-alloc 5/15, primitives 3/15, native-blas 2/15, lookup
2/15, unattributed 3/15). Samples in the
setupwindow are excluded. Theunattributed causes are classified as "never entered R (libc / linker)" and
"unresolved stack". Nested benchmark names (
nbody/nbody_naive) and arecording without
MARK execute(skipped with a warning) behave asintended. It has not been run on a real recording.
Changes visible to users (bench-owned, not reverted)
environment→fingerprint. Samples carrydirection/iteration/extrainstead oflower_is_better/outlier.Variants are
{"pairs": ...}. Iterations losefailure/runtime. Old JSONreports probably cannot be loaded by
showunder the new bench.--dirlayout:<suite>/<bench>/run/0/→<suite>/<bench>/run0/1/.environment.json→fingerprint.json.--include, bench now filters before it shuffles, so a subset runs ina different order than before. The full corpus order is unchanged.
--listnow honours--include/--exclude.rather than per iteration.
nicenesswas added, and theorder changed.
@dataclasson aParamssubclass is now an error, which affectsdownstream drivers built on
rbench.Params(e.g. VMIL26's).Open questions
adopt bench's new schema and update CI and consumers instead?
--slaverelies on R core keeping the deprecated alias. If R-devel everdrops it, R will warn about an unknown option and echo the script. Should
the harness command be chosen per R version instead (needs a version source
other than
--versionfor R-devel)?categorize.Rreports per recording. Should it also emit VMIL26'sbenchmark-level profile (median over runs, renormalised), or leave that to
the dashboard?
🤖 Generated with Claude Code