The TiffinBox BuildOne system, every chapter
0 / 0

Workbench / The TiffinBox Build

S27 · V2·27

Budgets That Gate Changes

Volume 2, chapter 27. The performance work of stages 18–25 becomes rules a change must pass. One measurement module times what the kitchen display's users notice at 500 orders on the throttled tablet profile: bytes, first cards, blank frames, all cards, LCP, the longest start-up task, a tap's latency as INP counts it, the time until its result is on screen, and long tasks while orders arrive. Per-view budgets in budgets.json are checked on the median of three runs (about 50 s); removing the plain view's chunking pushed its start-up task from 73 to 163 ms and failed. A Baseline policy, checked against web-features, found two newly available features the display depended on without a fallback: light-dark(), whose absence would have removed every colour, and AbortSignal.timeout, whose absence broke search and every action. Both now have fallbacks, proved by tests that take the feature away.

6 parts · ~6 min to read
Updated Suggest a correction

Stage 27: budgets that gate changes

The brief

What you'll build.

  • web-tests/suite/perf.py: one measurement of a view (CPU slowed 4×, rate adjustable): JavaScript size, first cards, blank frames after first paint, all cards, LCP, the longest start-up task, a tap's Event Timing duration and phases, the time from the tap to the new status on screen, and long tasks while ten orders arrive; python3 perf.py prints three runs per view;
  • budgets.json and test_budgets.py: per-view budgets on the median of three runs, marked perf (run.sh -m perf);
  • web-tests/baseline.mjs with web-features 3.43.0 (pinned): every platform feature the CSS and TypeScript use, its Baseline status, and baseline-policy.json: exceptions below "widely available", each with a reason; run by check-js.sh;
  • fallbacks the policy required: the colour tokens restated under @supports not (color: light-dark(#000, #fff)); timeoutSignal() in lib.ts for AbortSignal.timeout;
  • test_baseline.py: each fallback proved by removing the feature in Chromium.

Why a real company needs this. Performance and browser support decay one reasonable change at a time. A number in a document is ignored; a number that fails the build is a conversation at review time, when the change is cheapest to reconsider. The same goes for "we support these browsers": unless something checks it, the first report is a customer's broken screen.

Why now. Chapter 27 is performance: lab and field data, Core Web Vitals, loading and running costs, budgets. The build has measured a lot since stage 18; nothing yet stops a change from undoing it.

What you'll have at the end.

  • budgets per view, enforced, with a planted regression to show they bite;
  • a Baseline policy that names every newer feature and how the display copes without it;
  • ADR-0029: budgets and browser support.

Theory to own

  1. Which metrics, for which screen. What does each of LCP, INP and a custom "result on screen" measure on the kitchen display, and what does each miss? (Companion, Gaps 1.)
  2. Lab emulation. What does 4× CPU throttling change, and what doesn't it? (Companion, Gaps 2.)
  3. Noise and budgets. What can a median of three runs detect? (Companion, Gaps 3.)
  4. Baseline. What do "widely available" and "newly available" mean, and what should a page do with a feature that's only newly available? (The chapter, and web.dev's Baseline definition.)
  5. Fallbacks for custom properties. Why doesn't writing a plain value before light-dark() protect a custom property? (Companion, drill D4.)

Build it

Step 1: one measurement, everything users notice

Write perf.py's measure(browser, url, n, place, view, rate=4). Install observers before the page loads (long tasks, LCP, Event Timing with a 16 ms threshold, a frame sampler counting visible cards). Load the display with 500 open orders, wait until every card is shown and the status says Live. Then tap Accept on the tenth card and record Event Timing's longest entry and the time until the card's status changes on screen (a MutationObserver started on pointerdown, read in the next animation frame). Then let ten orders arrive and count long tasks. Run three times per view and print the table.

Checkpoint. python3 web-tests/suite/perf.py prints three runs for each view.

Step 2: budgets, as tests

Write budgets.json from the table, with headroom, and test_budgets.py: start a server of its own with 500 orders, measure each view three times, and fail with every metric over budget, its median, its budget and all three runs. Mark it perf and exclude it by default in pytest.ini. Then plant a regression: set the plain view's chunk size from 50 to 5,000.

Checkpoint. The budgets pass; the planted regression fails with a message that says what and by how much.

Step 3: a Baseline policy, checked

Write baseline.mjs: a list of features and the patterns that show the build uses them (@layer, light-dark(, :user-invalid, AbortSignal.timeout, requestIdleCallback, wakeLock, …), each looked up in web-features. Policy: Baseline widely available; anything else needs an entry in baseline-policy.json with a reason. A stale exception (a feature no longer used) is an error too. Run it with no exceptions first.

Checkpoint. You know every feature below the policy, and which of them the display depends on.

Step 4: fallbacks, proved

Add timeoutSignal(ms) to lib.ts (the native function when present, otherwise an AbortController aborted by a timer with a TimeoutError) and use it in getJson and postCommand. Restate every colour token under @supports not (color: light-dark(#000, #fff)): plain light values on :root, dark values under the media query and under data-theme="dark". Write test_baseline.py: serve the stylesheet with light-dark( renamed, so Chromium treats it as unsupported, and compare computed colours with the normal page in both themes and with a stored preference; delete AbortSignal.timeout in an init script and search the menu and accept an order. Then remove each fallback and run the tests again.

Checkpoint. The tests pass with the fallbacks and fail without them.

Senior and architect lens

1. Budget what users notice, per screen. LCP and INP are good shared signals; the kitchen display also needs "no blank frames" and "time to the result", because those are what cooks see.

2. ADR-0029: budgets and browser support. Write it with these points:

  • Budgets: per view in budgets.json, medians of three runs at 4× CPU and 500 orders; lowered when a change improves a number, raised only with an ADR; deterministic metrics (bytes) tight, timing metrics with headroom.
  • Trend: every CI run's numbers kept, so drift below the budget is visible (Companion, drill D2).
  • Browser support: Baseline widely available; exceptions in baseline-policy.json, each with how the page copes and a test that removes the feature; stale exceptions fail the check.
  • Field data: stage 32's RUM confirms the lab numbers on real devices; the lab can't replace it.

3. Thresholds lie at the edges. No long task at full speed, 170 ms at 4×; 48 ms chunks that aren't long tasks but drop frames. Look at distributions and frames, not only at threshold counts.

4. A fallback without a test is a hope. Both fallbacks were written in minutes; the tests that remove the feature are what make them trustworthy for years.

5. Noise is a design input. Budgets with headroom catch big mistakes cheaply; small regressions need many runs, quieter machines, deterministic metrics or field data. Choose knowingly.

What breaks first, and when it's addressed:

Pressure What breaks Where it's addressed
CPU emulation only network, GPU and memory limits of real tablets unseen stage 32 (RUM from the kitchen's devices)
assets aren't cached or compressed repeat visits pay full download; budgets measure only cold loads stage 31 (hashed assets, compression, CDN)
budgets cover the kitchen display only the customer pages can get slower unnoticed stage 33 (release budgets for customer journeys)
the framework views' start-up tasks are 100–280 ms taps during start-up wait recorded in the ADR; revisited if a framework view becomes the default

Evidence

  • perf.py's table for the three views is in the README, with the tap-latency phases.
  • run.sh -m perf passes; the planted chunk-size regression fails with the start-up task over budget.
  • baseline.mjs output with no exceptions and with the policy; check-js.sh fails on an undocumented feature.
  • test_baseline.py passes, and fails without each fallback.
  • ADR-0029 is committed.

Carry forward

  • perf.py and budgets.json gain the customer journeys in stage 33, and stage 32 compares them with field data.
  • baseline-policy.json is reviewed whenever web-features is updated; exceptions are removed as features become widely available.
  • timeoutSignal() is the only way the client creates timeouts; stage 29's offline queue uses it.
  • The perf marker separates slow checks from the quick suite; stage 30's CI runs both.