Skip to content

chore: Performance benchmark harness - #10787

Merged
reidbarber merged 20 commits into
mainfrom
perf-benchmark-harness
Nov 12, 2026
Merged

reidbarber merged 20 commits into
mainfrom
perf-benchmark-harness

Conversation

@reidbarber

@reidbarber reidbarber commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

This adds a benchmark suite for measuring performance in ways that actually affect user experience: how fast components appear, how quickly interactions update the screen, and how smoothly collections scroll. Some proposed changes may, for instance, reduce re-renders or cut out work in specific narrow cases, but we'd rather be able to measure if changes have a perceivable impact in real-world scenarios.

Benchmarks run production React builds in Chromium (via Playwright) against realistic interactive fixtures. The initial suite includes 60 scenarios covering mounting, keyboard and pointer navigation, filtering, sorting, large selections, keyboard drag and drop, incremental loading, virtualized scrolling, column and container resizing, collection updates, forms, menus, and dialogs. It is intended to be run locally where you can have an agent compare potential changes against a baseline. Builds and results are git-ignored and there is currently no CI integration, although we could use this for regression tests in CI in the future if we wanted to. Everything in this PR is self-contained in perf/.

The harness supports:

  • Immutable named production snapshots, with build provenance and compatibility checks, for comparing library changes using the same benchmark implementation.
  • Trusted browser input and assertions that the expected content, selection, focus, and layout have completed.
  • Paired comparisons across fresh browser launches, with warmups, interleaved baseline/candidate trials, shuffled scenario order, confidence intervals, and practical significance thresholds.
  • Results broken down by browser launch to help identify drift, order effects, and unusually slow launches.
  • Calibration with known delays, repeated A/A validation, and a yarn perf confirm command to check whether improvements or regressions hold across additional runs.
  • Long Animation Frames attribution and DOM mutation counts as supporting measurements.
  • Separate diagnostic traces with matching warmups, measurement-window markers, and summaries of JavaScript, style, layout, paint, and garbage collection work.
  • Configurable workload sizes and CPU throttling.
  • Per-fixture scenario drivers and documentation for adding new benchmarks.

Interaction measurements capture the time from input through the expected state change and a rendering opportunity. Scrolling uses browser-driven gestures and measures the average interval between main-thread animation-frame callbacks, with tail intervals and estimated missed callbacks reported as supporting measurements. Diagnostic traces and Long Animation Frames help explain where time was spent, while DOM mutation counts show changes in DOM work.

See perf/README.md for more details. This is also the guidance that agents will use.

Example run results:

Potential future improvements:

  • Add S2 fixtures
  • Integration into CI
  • Report memory retention (watch JS heap size over time to catch memory leaks)

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices
  • I understand every change in this PR and can explain why it's there.
  • If AI-assisted, I followed our AI contribution guidance and pointed my assistant at AGENTS.md.

📝 Test Instructions:

Ask your agent to try it out on some performance-related PRs or changes. See perf/README.md for more details.

🧢 Your Project:

- Table sorting, filtering, and clearing filters.
- Row/select-all checkboxes, cell menus and dialogs, and focus restoration.
- Keyboard and pointer navigation in ComboBox and Select with rich options.
- Variable-height virtualization: mount, scroll, and resize.
- Collection changes: append, delete selected records, and replace datasets.
- Tree interactions: expand, navigate, and collapse.
- Only check layout-reading completion conditions (scroll position, variable-height
  geometry) once per animation frame, so the check no longer forces synchronous
  layout while table.scroll is being timed.
- Write results.json even when building the report fails, and record the run as
  failed instead of losing its samples.
- Mark the report rewritten after each block as in progress, not failed.
- Report --trace failures and interruptions separately, without invalidating
  completed measurements.
- Show "n/a" instead of "undefined%" when the base median is 0.
- Add perf/drivers.mjs, which groups each scenario's setup, spec, and checks by
  fixture and action (table.scroll → drivers.table.actions.scroll). Previously
  this logic was spread across runner.mjs as branches on scenario IDs.
- Make the runner's setup and measurement steps generic. Measured input now comes
  from the spec's event, target, key, and wheel settings instead of hard-coded
  scenario IDs. ComboBox filtering keeps its own input routine.
- Use one check for both scroll scenarios: all 12 wheel events and at least 10
  frame intervals. table.scroll now also requires every wheel event.
- Add driver tests checking that every scenario has a driver, every driver is
  listed in scenarios.mjs, and specs can be passed to the page.
- Add drivers.mjs to the harness hash and a short "Adding a scenario" README section.
…en gesture

- Have Chromium drive scrolling with Input.synthesizeScrollGesture: 4,000 px at
  2,000 px/s, with wheel events generated at the browser's frame rate. This
  replaces 12 Node-driven wheel steps with 32 ms pauses, whose idle gaps hid
  jank: at 4x CPU, table.scroll misses about 12% of frames that the old input
  didn't show. Each trial now collects about 240 frame intervals instead of
  about 54.
- Require each scroll to reach its distance, receive a stream of wheel events,
  and collect frame intervals covering at least 90% of the gesture, so heavy
  jank still produces a score instead of failing the run. Remove the unused
  eventCount option.
- Compare scroll scenarios on frameMean, the average frame-callback interval.
  frameP95 jumps between whole frame periods once some frames are late. In 8-block
  A/A runs it varied by up to 6.35 ms (39%) at 4x CPU, versus at most 0.32 ms
  (3.5%) for frameMean.
- Keep frameP95 as a supporting report column, and add a missed-frames estimate
  per trial.
- Lower the --frame-threshold default from 2 ms to 0.25 ms, so the 5% relative
  threshold applies at normal display rates (about 0.42 ms at 120 Hz). Every A/A
  run on an M2 Max came out within threshold at 1x and 4x CPU.
- Update the README and add tests for missed frames and frameMean comparisons.
- Compare each browser launch with itself: its change is the candidate's
  median trial minus the base's, so drift between launches cancels. Report the
  Hodges–Lehmann estimate of those changes and an exact Wilcoxon signed-rank
  interval at the smallest confidence of at least 95% (96.1% for 8 blocks),
  shown next to the interval. Fewer than 6 blocks stays inconclusive. This
  replaces the pooled-trial bootstrap, which simulated A/A runs showed was too
  narrow without launch drift (7–10% false exclusions at a nominal 5%) and too
  wide with it. The new intervals stay at or below their nominal rate in both
  cases.
- Keep base and candidate pages open side by side and alternate their trials
  within each block in ABBA order, alternating which arm leads between blocks.
  Record each sample's position, and bump the results schema to 2.
- Require an even --blocks for compare, calibrate, and validate so each arm
  leads equally often.
- Add `yarn perf validate --build <name> --runs <n>`, which runs repeated A/A
  comparisons with different seeds and reports how often intervals excluded
  zero, versus the expected rate and the binomial chance of seeing at least
  that many.
- Add tests for the interval maths, simulated A/A error rates with and without
  launch drift, binomial tails, and the report's confidence column. Update the
  README, including the scroll threshold calibration recomputed with the new
  intervals.
- Add a "Changes by browser launch" table to compare reports. For each
  scenario it shows each launch's paired change (candidate median minus base
  median), which arm led that launch's ABBA trials, medians over base-led and
  candidate-led launches, and each launch's start time. This makes drift,
  order effects, and single outlier launches visible.
- Shuffle scenario order separately for each launch with a seeded shuffle,
  replacing the one-position rotation that left most scenarios at similar
  positions. Record each scenario's position and start time in the results
  order.
- Add `yarn perf confirm --results <id> --runs <n>`. It reruns scenarios from
  a completed compare with the same builds and settings but new seeds, by
  default the ones that reported an improvement or regression. The run count
  is fixed before any run starts, and every run completes. The summary puts
  each rerun beside the original and marks the scenario confirmed, not
  confirmed, or unresolved.
- Update --seed help and the README, add a confirm step to "Comparing a
  change", and add tests for the shuffle, the per-launch table, and confirm
  verdicts.
- Count DOM mutations per trial: mutation records, plus nodes added and
  removed, from the input until the rendering opportunity. Report the median
  per arm. Counts repeat exactly between trials, so a difference between arms
  shows the DOM work changed even when times are within noise.
- Mark the measurement window in diagnostic traces with User Timing measures
  (`bench:window` and `bench:ready`), so the DevTools Timings track shows what
  the score covered. Only --trace reruns add them.
- Run the same warmups before each traced trial as before measured trials.
  Previously traces captured a cold first trial.
- Add trace.mjs, which splits the renderer main thread's time inside the
  window into script, style, layout, paint, GC, and other work using
  innermost-event self time, and counts style and layout forced from script.
  Show it in a "Diagnostic traces" report table, and record task boundaries
  (`toplevel`) so scheduling overhead appears as other work.
- Add tests for the trace breakdown and the new report sections, and
  document traces and mutation counts in the README.
@nwidynski

nwidynski commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Lmao, I guess we both got fed up with reviewing at roughly the same time! This is awesome ❤️

- `table-measured.mount` — mount a virtualized 1,000-row table with measured heights and wrapping labels.
- `table-measured.narrow` — narrow the labels column and measure row growth.
- `table-measured.widen` — widen the labels column and verify rows shrink.
- `table-measured.other-column` — resize another column while measured rows remain tall.
- `table-measured.container` — narrow the table container and verify column widths and row geometry settle.
- `table-data.focus` — keyboard cell navigation without selection.
- `table.scroll-deep` — scrolling after traversing 4,000 rows.
- `table-measured.resize-animation` — continuous width changes scored by frame cadence.
- `dnd.modality-type` — typing after pointer input, plus `dnd.type` as a keyboard-mode baseline.
Remove or replace:
- Remove `form.dialog`; `table-cells.dialog` covers the same modal and
  autofocus path against a larger DOM.
- Replace `select.keyboard`, which repeated `listbox.focus`, with
  `select.choose`: Enter saves a controlled value, closes the
  500-option popup, and returns focus to the trigger.

Change:
- `table-measured.container` and `resize-animation` start from fitted
  labels that share the flexible width, so narrowing the container
  rewraps labels and re-measures rows instead of only shrinking an
  empty column.
- Split `combobox.filter` into single keystrokes: `filter` types `9`,
  and the new `combobox.narrow` types a second `9` after the first
  filter settles. This removes the fixed 75 ms pause from the window.
- Add `variable.scroll-deep`, which traverses 160,000 px before the
  measured scroll. Keep `table.scroll-deep`, which scores well above
  the shallow scroll.
- `calibrate` now also adds 16 ms of work to keydown/pointerover
  dispatch (`listbox.focus`, `select.hover`) and 4 ms to every scroll
  frame (`table.scroll`, `variable.scroll`); the report says what
  was added.
- Label `dnd.type` as the baseline for `dnd.modality-type`.
- Document that `frameMean` cannot fall below the display refresh
  period, so it detects only work that delays frames.
- `table-measured.resize-drag`: drag the labels column resizer 200 px
  narrower in 2 px steps, scored by frame cadence. Widths stay
  controlled through `onResize`.
- `reorder.drag-start`, `reorder.drag-move`, `reorder.drop`: keyboard
  drag, move, and drop in a 200-item GridList that uses
  `useDragAndDrop`. Pointer drags are not covered because Playwright
  emulates native drag events.
- `table.select-all` and `table.select-range`: Ctrl/Cmd+A over 10,000
  virtualized rows, and a shift-click that selects a 4,001-row range.
  The table now reports its selection size.
- `combobox-virtual.open`, `.filter`, `.keyboard` and
  `select-virtual.open`, `.choose`: 10,000 options in virtualized
  popups with fixed 52 px rows.
- `infinite.scroll`: scroll a virtualized table that appends 50-row
  pages through `TableLoadMoreItem`, scored by frame cadence.
- `table-cells.mount`: mount 100 rows, each with a checkbox, menu, and
  dialog trigger.
- Add an action `cleanup` hook to the runner. Reorder trials use it to
  cancel an unfinished drag, because drag state is global and
  survives the fixture remount.
@rspbot

rspbot commented Oct 16, 2026

Copy link
Copy Markdown

Agent Skills Changes

Modified (9)
Install

React Spectrum S2:

npx skills add https://d1pzu54gtk2aed.cloudfront.net/pr/6e6fb8b415290e87884f33e25a181f27facce980/

React Aria:

npx skills add https://d5iwopk28bdhl.cloudfront.net/pr/6e6fb8b415290e87884f33e25a181f27facce980/

@LFDanLu LFDanLu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it myself on #10768, seems pretty handy. Any particular inspiration on the approach? The scenarios and drivers seems quite through, any ideas on how we'd keep them up to date to include new cases/components/interactions/etc?

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to get in for initial usage.

It's a little hard to follow how all of it hangs together through scenarios. Maybe we can have an architecture diagram somewhere that describes it.

@reidbarber

Copy link
Copy Markdown
Member Author

@LFDanLu

Any particular inspiration on the approach?

No one place specifically, but I wanted to try to cut out as much noise as possible and capture the metrics that end users would actually notice if we improved. It seems like a lot of the benchmarks I've seen use jsdom, development React, or have some other quirks that make them not as useful.

I think the environment and the metrics we capture should help with that. This resource was pretty useful: https://web.dev/articles/user-centric-performance-metrics

Some of the statistical concepts took some inspiration from this project from Google: https://github.com/google/tachometer

And the initial scenarios are inspired by our existing reported performance issues.

any ideas on how we'd keep them up to date to include new cases/components/interactions/etc?

I was thinking for future ones, agents could just create one-off scenarios where needed, and we could save them if they seemed useful to keep.

@devongovett

Copy link
Copy Markdown
Member

Is there a summary of what scenarios are covered and what is being measured?

@reidbarber

reidbarber commented Nov 3, 2026 •

Copy link
Copy Markdown
Member Author

@devongovett

Excerpts from the README:

Scenarios

Example: --scenario table.scroll,collection runs one table action and all collection-mutation actions.

Fixture filter Default workload Actions
listbox 100 items with labels, team, and status Mount, focus, select, unrelated parent update
combobox 500 options with an icon, label, and description Open, type 9 to filter, type a second 9 to narrow, keyboard and pointer navigation
select 500 rich options in a controlled Select Pointer navigation in an open popup, choose an option and close the popup
combobox-virtual 10,000 rich options in a virtualized popup, fixed 52 px rows Open, type 9 to filter, keyboard navigation
select-virtual 10,000 rich options in a virtualized, controlled Select Open, choose an option and close the popup
table-data 100 nonvirtualized rows × six columns Sort, filter by 9, clear the filter, move cell focus without selection
table-cells 100 nonvirtualized rows × six columns with controls Mount, select one/all rows, open/close a menu or dialog
table 10,000 virtualized rows × six columns, fixed 40 px rows Mount, scroll 4,000 px near the top or after traversing 4,000 rows, update one visible record, select all rows, shift-click a 4,001-row range
infinite A virtualized table that loads 50-row pages from 500 prepared records Scroll 4,000 px while two more pages load
table-measured 1,000 virtualized rows × eight columns, measured heights and wrapping labels Mount, drag the labels resizer, narrow/widen labels, resize another column, narrow or continuously animate the container with fitted labels
variable 10,000 virtualized items with wrapping descriptions Mount, scroll 4,000 px near the top or after traversing 160,000 px, narrow from 600 to 360 px
collection 100 GridList records, a prepared 50-record page, and a replacement dataset Append, delete five selected records, replace the dataset
tree 20 projects with 50 files each Expand, navigate into a project, collapse
resize 500 nonvirtualized rows × six flexible columns Mount, narrow the container from 960 to 660 px
form 30 mixed text fields, checkboxes, and switches Mount, type in a controlled field
reorder 200 GridList items with drag buttons and useDragAndDrop reordering Start a keyboard drag, move the drop target, drop
dnd 200 draggable cards beside an independently controlled text field Type after pointer input, plus a baseline that types while already in keyboard mode

See scenarios.mjs for all scenario descriptions.

Primary Metrics

Lower values are better for both primary metrics:

Metric Used for Meaning
opportunity Discrete actions Time from the initiating trusted event to two animation-frame callbacks after the expected DOM/focus state is observed. A rendering-opportunity proxy, not proof that pixels were presented.
frameMean table.scroll, table.scroll-deep, variable.scroll, variable.scroll-deep, infinite.scroll, table-measured.resize-drag, table-measured.resize-animation Mean animation-frame callback interval within a trial. Measures main-thread callback cadence, not compositor frame delivery. The action's total duration is not the score.

Supporting Metrics

Measurement Interpretation
Semantic readiness (ready) First observation of the expected DOM/focus state, through mutation/focus observation or the frame loop. Layout-dependent conditions run in the frame loop rather than mutation callbacks. This is not React render duration or paint time.
Event Timing Browser-reported event durations, input delays, processing times, and interaction IDs. Entries are grouped by interaction ID for observed maxima. Durations are quantized and short entries may be absent; missing entries are not zeros. These scripted interactions do not measure field INP.
Long animation frames (LoAF) Frames of at least 50 ms overlapping the window, with blocking duration, script, style/layout, and forced style/layout attribution. Scripts are listed only when they take at least 5 ms. A trial with no long frame has no attribution, not zero cost. Raw entries are retained; sources are minified production code.
rAF interval p95 and maximum Supporting per-trial frame-interval statistics. The report shows the median p95 and worst interval. Intervals cluster around whole frame periods, making the tail percentile less stable than the mean for comparisons.
Missed frames Estimated from intervals spanning multiple periods, using the trial's median interval as the period. This assumes fewer than half the callbacks are late and does not count compositor-dropped frames.
DOM mutations Mutation records and nodes added/removed from input to rendering opportunity. Helps identify changed DOM work even when timing is noisy; does not capture re-renders that leave the DOM unchanged.
@reidbarber
reidbarber added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit 23e1590 Nov 12, 2026
31 checks passed
@reidbarber
reidbarber deleted the perf-benchmark-harness branch November 12, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7 participants