Render metrics

Render metrics

React Compiler is meant to keep components from rendering when nothing they use changed. Nothing in make ci checks that it does: a context that hands out a new object every render, or an effect that sets state, re-renders a whole subtree and every test still passes. make render.metrics counts the renders, so a change can be compared with the commit before it.

Use

git worktree add ../warpkit-main main        # a checkout of the base
(cd ../warpkit-main && make render.metrics OUT=../main-renders.json)
make render.metrics OUT=../branch-renders.json
make render.compare A=../main-renders.json B=../branch-renders.json

The comparison prints commits and renders per scenario, marks a change no larger than either side's spread "within noise", and lists the components whose counts changed most. Quote the table in the commit message of a change meant to cut renders, or of one that adds them on purpose.

What it measures

e2e/render-metrics/counter.ts installs React's DevTools hook before react-dom loads, so React reports every commit to it. For each commit it counts the components whose render function ran. A component React skipped is not counted.

e2e/render-metrics/render-metrics.spec.ts has the scenarios: a load of the landing page, the dashboard, notes and settings (everything until no commit has come for 1.5 s), and typing in the display name field (the renders after the page settled). Add a scenario where a page is slow or a change targets it.

scripts/render-metrics.ts run runs the scenarios five times on the e2e dev server and keeps, per scenario, the median run and the spread from the lowest to the highest count. Page loads vary a little on a busy machine (whether data lands before or after hydration changes how React batches commits); typing does not.

Reading the numbers

  • The dev server runs React in <StrictMode>, which renders twice on mount. The counts are higher than in production, the same way on both sides of a comparison.
  • Measure both sides on an equally quiet machine: the spread grows with load, and a change inside it is not a finding.
  • Anonymous is a component without a name: an inline arrow function or a library's unnamed component.