Skip to content

perf: count only user-mode instructions in benchmarks - #14908

Draft
Kha wants to merge 1 commit into
masterfrom
push-wvqytytpskru
Draft

perf: count only user-mode instructions in benchmarks#14908
Kha wants to merge 1 commit into
masterfrom
push-wvqytytpskru

Conversation

@Kha

@Kha Kha commented Aug 24, 2026

Copy link
Copy Markdown
Member

This PR restricts the instructions benchmark metric to user mode, which should further reduce noise.

This PR restricts the `instructions` benchmark metric to user mode, making it far less noisy and independent of the machine it is measured on. Reported instruction counts drop by a one-time step of roughly 5% on elaboration-heavy benchmarks and considerably more on short, load-dominated ones; comparisons from this commit onwards are unaffected.

`tests/measure.py` requested the bare `instructions` perf event, which counts user and kernel mode together wherever `perf_event_paranoid` permits it. Kernel-mode instructions track page cache state, memory pressure and kernel version rather than anything Lean does, and they carry practically all of the variance: measured over repeated runs of `elab_bench/big_match`, the total has a relative standard deviation of 2.01% while its user-mode part has 0.02% and its kernel-mode part 11.41%. Their cost is already covered, more directly and more quietly, by `task-clock`, `wall-clock`, `maxrss` and the `bytes .olean` metrics.

Requesting `instructions:u` explicitly also pins down what the metric means. `perf` silently degrades an unrestricted counter to its user-mode variant when it lacks permission, and `get_perf_result` accepts that under the same metric name, so the quantity being recorded depended on the measuring machine and a change in its configuration would have registered as a large improvement across every series at once. The `:u` modifier is available at every `perf_event_paranoid` level, so the metric is now comparable between the benchmark machine, CI and developer machines.

`cycles` deliberately keeps counting both modes, alongside the other cost metrics.

Co-Authored-By: Claude <noreply@anthropic.com>
@Kha

Kha commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Aug 24, 2026

Copy link
Copy Markdown

Benchmark results for d75ee59 against 16e77c4 are in. There are significant results. @Kha

  • build//instructions: -320.2G (-2.79%)

Large changes (48✅)

  • compiled/const_fold//instructions: -834.4M (-11.62%)
  • compiled/deriv//instructions: -17.9M (-0.27%)
  • compiled/http_server_tcp//instructions: -72.2G (-52.02%)
  • compiled/incr_header_load//instructions: -359.6M (-49.71%)
  • compiled/io_compute//instructions: -34.9M (-0.32%)
  • compiled/iterators//instructions: -8.3M (-1.52%)
  • compiled/rbmap_checkpoint//instructions: -78.4M (-0.62%)
  • compiled/watchdogRss//instructions: -2.1G (-8.18%)
  • elab/big_beq//instructions: -489.6M (-5.63%)
  • elab/big_deceq//instructions: -482.8M (-11.65%)
  • elab/big_deceq_rec//instructions: -485.2M (-8.82%)
  • elab/big_match//instructions: -486.6M (-4.89%)
  • elab/big_match_nat//instructions: -479.7M (-10.30%)
  • elab/big_match_nat_split//instructions: -482.7M (-4.71%)
  • elab/big_match_partial//instructions: -499.3M (-3.67%)
  • elab/big_struct//instructions: -145.8M (-5.79%)
  • elab/cbv_dedup//instructions: -239.0M (-8.07%)
  • elab/charactersIn//instructions: -435.4M (-1.38%)
  • elab/delayed_assign//instructions: -479.6M (-14.35%)
  • elab/delayed_sharing//instructions: -476.6M (-17.92%)
  • and 28 more

Medium changes (40✅)

  • build/module/Std.Data.DTreeMap.Internal.Lemmas//instructions: -1.5G (-0.70%)
  • compiled/ilean_roundtrip//instructions: -35.4M (-0.16%)
  • compiled/liasolver//instructions: -15.0M (-0.45%)
  • compiled/nat_repr//instructions: -16.6M (-0.05%)
  • compiled/phashmap//instructions: -17.1M (-0.20%)
  • compiled/qsort//instructions: -16.6M (-0.11%)
  • compiled/rbmap//instructions: -9.2M (-0.11%)
  • compiled/rbmap_checkpoint2//instructions: -15.9M (-0.18%)
  • compiled/rbmap_fbip//instructions: -8.8M (-0.13%)
  • compiled/rbmap_library//instructions: -17.9M (-0.19%)
  • compiled/select//instructions: -42.0M (-1.53%)
  • compiled/server_startup//instructions: -32.8M (-9.17%)
  • compiled/sigmaIterator//instructions: -4.4M (-0.16%)
  • compiled/treemap//instructions: -16.1M (-0.09%)
  • compiled/unionfind//instructions: -14.7M (-0.07%)
  • compiled/workspaceSymbolsNewRanges//instructions: -12.6M (-1.89%)
  • elab/big_beq_rec//instructions: -499.8M (-3.26%)
  • elab/big_do//instructions: -160.8M (-0.88%)
  • elab/big_struct_dep1//instructions: -145.4M (-2.97%)
  • elab/bv_decide_incremental//instructions: -6.7G (-5.93%)
  • and 19 more
  • and 1 hidden

Small changes (2532✅)

  • build/lakeprof/longest rebuild path//instructions: -6.2G (-1.04%)
  • build/module/Init.BinderNameHint//instructions: -19.8M (-6.06%)
  • build/module/Init.BinderPredicates//instructions: -31.6M (-1.51%)
  • build/module/Init.ByCases//instructions: -25.9M (-3.32%)
  • build/module/Init.CbvSimproc//instructions: -49.5M (-2.39%) (reduced significance based on absolute threshold)
  • build/module/Init.Classical//instructions: -37.2M (-3.50%)
  • build/module/Init.Coe//instructions: -30.6M (-4.48%)
  • build/module/Init.Control.Basic//instructions: -32.7M (-1.52%)
  • build/module/Init.Control.Do//instructions: -21.7M (-4.25%)
  • build/module/Init.Control.EState//instructions: -24.8M (-3.62%)
  • build/module/Init.Control.Except//instructions: -30.3M (-2.17%) (reduced significance based on absolute threshold)
  • build/module/Init.Control.ExceptCps//instructions: -26.7M (-2.47%)
  • build/module/Init.Control.Id//instructions: -21.8M (-4.63%)
  • build/module/Init.Control.Lawful.Basic//instructions: -38.8M (-1.84%) (reduced significance based on absolute threshold)
  • build/module/Init.Control.Lawful.Instances//instructions: -83.9M (-1.26%) (reduced significance based on absolute threshold)
  • build/module/Init.Control.Lawful.Lemmas//instructions: -27.2M (-3.93%)
  • build/module/Init.Control.Lawful.MonadAttach.Instances//instructions: -35.6M (-2.20%)
  • build/module/Init.Control.Lawful.MonadAttach.Lemmas//instructions: -32.5M (-3.26%)
  • build/module/Init.Control.Lawful.MonadAttach//instructions: -22.9M (-4.68%) (reduced significance based on absolute threshold)
  • build/module/Init.Control.Lawful.MonadLift.Basic//instructions: -21.4M (-6.64%)
  • and 2512 more

@github-actions github-actions Bot added toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN labels Aug 24, 2026
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Aug 24, 2026
@leanprover-bot

leanprover-bot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Aug 24, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-manual CI has verified that the Lean Language Reference builds against this PR builds-mathlib CI has verified that Mathlib builds against this PR mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants