Skip to content

Re-pin bench, run on R 3.x, add the perf category classifier - #3

Open
MatejKocourek wants to merge 1 commit into
mainfrom
r-speed-prep
Open

MatejKocourek wants to merge 1 commit into
mainfrom
r-speed-prep

Conversation

@MatejKocourek

Copy link
Copy Markdown
Collaborator

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:

  1. The bench pin is unreachable. Both drivers pin PRL-PRG/bench at
    7bc2cbb, which no bench branch contains any more (bench's history was
    rewritten). GitHub still serves it, but it can be garbage-collected at any
    time, and then uv run --script rbench.py stops resolving.
  2. The harness command line assumed R ≥ 4.0 (--no-echo), and the harness
    called gc(full = TRUE), an argument R only has from 3.5.0.
  3. There was no way to turn a recording into category shares.
    rbench_perf.py records perf and the instrument harness prints MARK
    lines, but the classifier that maps frames to categories lives only in the
    VMIL26 paper artifact.

What changed

bench re-pinned to 4639a83 (bench main), drivers adapted

bench's API changed a lot between the two commits (2026-09/10 refactor). The
drivers were adapted to it without changing what they measure:

Was (7bc2cbb) Now (4639a83)
@dataclass(frozen=True) class Params(SharedBenchParams) plain subclass: bench.Params makes every subclass a frozen kw-only dataclass, and decorating it again is a TypeError
Regex(...) + .with_harness(monitor=_iteration_monitor) framing a streaming harness RegexMetric(..., 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 bench's policies now count processes; .with_warmup(0).with_runs(1) plus a small InProcessWarmup controller that flags the first warmups iterations of each process
intrinsic elapsed sample, .with_process_metric(max_rss()) explicit .with_metric(..., Time(), max_rss()) (Metric and ProcessMetric merged)
"no iterations parsed" failure built into the harness source 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, so RBENCH_PROFILE is recorded in the fingerprint (JSON and the CSV preamble) and said once on stderr
SummaryReporter(Results() & Summary() & GeomeanSummary(axis, metrics="runtime")) passed into default_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 with out_dir PerfRecord(root, ...) as a controller (.with_controller); it writes into the same execution_dir the dir reporter uses
--numa, --csv-merge from bench gone from bench; re-added in rbench.Params (numactl prefix in _r_cmd; merge in the driver's CSV reporter)
--show FILE bench now has a show FILE subcommand; rb.main() rewrites --show FILE to it
bench's CSV schema bench's new CSV has a different column order and an outlier column that only appears when an outlier is flagged. RbenchCsvReporter writes the old schema exactly, so downstream readers (CI's failure check, r-speed) are unaffected

rbench_perf.py now passes override=True where it replaces a base_app
setting, because bench warns otherwise. It also drops the geomean block from its summary, since there is no runtime metric to rank.

R 3.x

  • R --no-echo → R --slave in _r_cmd (and in the READMEs). R 4.0 renamed
    the flag but still accepts --slave silently (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 subprocess
    at plan time (also for --list/--dry), and R-devel's --version prints no
    version number to parse.
  • gc(full = TRUE) → gc() in both harnesses. full was added in R 3.5.0
    (checked in R's SVN gc.Rd at R-3-4-0 vs R-3-5-0), where it defaults to
    TRUE. Before that, do_gc always collected every generation (R-3-4-0
    memory.c). The call does the same thing on every version.
  • Nothing else in harness.R / harness_instrument.R is newer than 3.0: no
    \(x), |>, raw strings, trimws, startsWith, isFALSE, ...length.
    marker.c uses only Rf_ScalarReal.

profile/: the category classifier

  • profile/perf-rules.R: VMIL26 analysis/perf-rules.R at 8b42516,
    byte-identical (sha256 e1168de6…). Provenance is in
    profile/ORIGIN.md.
  • profile/categorize.R: applies it the way VMIL26's categories.Rmd does
    (read_perf_frames → add_marked_region(read_perf_marks(stdout)) →
    classify_frames(rules) → sample_regions → keep region == "execute"). It
    reads an rbench_perf.py --dir tree and writes one row per (recording,
    category): suite, benchmark, variant, run, category, samples, kernel_samples, share, share_classified. share includes unattributed, so
    the categories and unattributed sum to 1. share_classified is VMIL26's
    per-run pct/100, which excludes it. --causes FILE writes the top N
    unclassified_causes() per recording. A recording with no MARK execute or
    no kernel samples is skipped with a warning.

README

The harness command line uses --slave, with a note on why. The profiling
section covers categorize.R. The driver example drops @dataclass and
mentions override=True, rb.main, and the licence note for profile/.

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 to
    the old pin.
  • rbench.py --include '^areWeFast/(bounce|mandelbrot)/run0' --runs 1 --iterations 2 --warmups 1 --csv --json --dir, old pin vs new: CSV header
    identical
    (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.
  • A failure corpus (one benchmark fails in iteration 0, one fails mid-run,
    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-merge carries over unmeasured benchmarks and writes the # merged:
    note. --show FILE renders a saved report. --dry --numa 0 shows the
    numactl prefix and --slave. --iterations 0 fails with "no iterations
    parsed from harness output", as before.
  • A real run of areWeFast/bounce, areWeFast/mandelbrot and
    shootout/nbody/nbody after the harness gc() change.
  • rbench_perf.py --help imports cleanly. No real perf recording: perf
    is not installed on the test machine. The plumbing was tested end to end
    with a stand-in perf on PATH: record runs the command, and script
    emits synthetic stacks timed inside the real MARK windows from
    marker.so. The output tree, perf-frames.csv, stdout with MARK lines
    and the CSV all came out as expected.
  • categorize.R on those synthetic recordings: the shares are exactly the
    constructed ones (mem-alloc 5/15, primitives 3/15, native-blas 2/15, lookup
    2/15, unattributed 3/15). Samples in the setup window are excluded. The
    unattributed causes are classified as "never entered R (libc / linker)" and
    "unresolved stack". Nested benchmark names (nbody/nbody_naive) and a
    recording without MARK execute (skipped with a warning) behave as
    intended. It has not been run on a real recording.
  • Not tested: the Docker image build, CI, and any R 3.x binary.

Changes visible to users (bench-owned, not reverted)

  • JSON report schema: environment → fingerprint. Samples carry
    direction/iteration/extra instead of lower_is_better/outlier.
    Variants are {"pairs": ...}. Iterations lose failure/runtime. Old JSON
    reports probably cannot be loaded by show under the new bench.
  • --dir layout: <suite>/<bench>/run/0/ → <suite>/<bench>/run0/1/.
    environment.json → fingerprint.json.
  • With --include, bench now filters before it shuffles, so a subset runs in
    a different order than before. The full corpus order is unchanged.
  • --list now honours --include/--exclude.
  • The console summary layout changed. Its counts are per process ("(1 runs)")
    rather than per iteration.
  • The CSV preamble keys follow bench's new probe: niceness was added, and the
    order changed.
  • @dataclass on a Params subclass is now an error, which affects
    downstream drivers built on rbench.Params (e.g. VMIL26's).

Open questions

  1. Is the stable CSV schema worth the extra reporter, or should r-benchmarks
    adopt bench's new schema and update CI and consumers instead?
  2. --slave relies on R core keeping the deprecated alias. If R-devel ever
    drops 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 --version for R-devel)?
  3. categorize.R reports per recording. Should it also emit VMIL26's
    benchmark-level profile (median over runs, renormalised), or leave that to
    the dashboard?
  4. Should the bench pin follow a tag? A branch tip can be rewritten again.

🤖 Generated with Claude Code

- 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>
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