Skip to content

Lesson 14 of 14 · 21m

Guardrails: Keeping It Fast After You Fix It

Performance decays by default — lab assertions per PR, field alerts per release, third-party governance, and the habits that keep gains.

Every successful performance project I've seen has the same epilogue: six months later, half the gains are gone. Nobody made a bad decision — marketing added a heatmap tool, a new carousel shipped with lazy slides, someone imported a utility library for one function. Performance decays by default. The fix isn't another project; it's guardrails that make regressions loud at the moment they're introduced.

Layer one: lab assertions on every PR

Lighthouse CI runs a production-like build against key routes and fails the check when metrics or resource sizes cross a line. Lab numbers are noisy — assert on medians of several runs and leave margin.

{
  "ci": {
    "collect": {
      "startServerCommand": "npm run preview -- --port 4173",
      "url": [
        "http://localhost:4173/",
        "http://localhost:4173/product/trail-runner-3",
        "http://localhost:4173/search?q=jacket"
      ],
      "numberOfRuns": 5
    },
    "assert": {
      "assertions": {
        "largest-contentful-paint": ["error", { "maxNumericValue": 2500 }],
        "cumulative-layout-shift": ["error", { "maxNumericValue": 0.1 }],
        "total-blocking-time": ["warn", { "maxNumericValue": 300 }],
        "resource-summary:script:size": ["error", { "maxNumericValue": 180000 }],
        "resource-summary:third-party:count": ["warn", { "maxNumericValue": 8 }]
      }
    },
    "upload": { "target": "temporary-public-storage" }
  }
}
npx @lhci/cli@0.14.x autorun --config=./lighthouserc.json

Pair it with the size-limit gate: size checks are deterministic and fast, so they catch bundle growth reliably; Lighthouse catches what size can't — a lazy hero, a render-blocking stylesheet, a layout shift.

Layer two: field alerts per release

Lab CI can't see real devices, A/B variants, or tags injected at runtime. Your RUM pipeline should compute p75 LCP, INP, and CLS per route and device class daily, and alert on a sustained regression — not one noisy day.

-- p75 LCP on mobile per route, per release, last 7 days
SELECT route, release,
       percentile_cont(0.75) WITHIN GROUP (ORDER BY value) AS p75_lcp,
       count(*) AS samples
FROM rum_metrics
WHERE name = 'LCP' AND device = 'mobile' AND ts > now() - interval '7 days'
GROUP BY route, release
HAVING count(*) > 500
ORDER BY route, release;

Every beacon carries the release SHA, so a regression points at a deploy window. Require a minimum sample size before alerting, or you'll page someone over twelve sessions from a bot.

Layer three: govern third parties

Third-party scripts bypass your bundler, your code review, and your CI — they get their own lesson, but the guardrail belongs here: an inventory with an owner and a business justification per script, async or post-interaction loading, a quarterly review, and LoAF-measured main-thread cost. A tag manager is a deployment pipeline marketing controls; give it a budget.

Layer four: budgets that travel with the metric

Size budgets (the size-limit lesson) and metric assertions fail differently: a size gate fires the moment a dependency lands, a metric gate fires when the user-facing number moves. You want both, because each catches what the other misses — a 40 KB dependency that never reaches the critical path shouldn't fail a build, and a 5 KB config change that turns off compression absolutely should. Wire the assertions to the same thresholds as the field scoring so "CI red" and "CrUX red" mean the same thing.

Make performance visible

  • Put p75 field vitals for top routes on the same dashboard as error rate and conversion.
  • Add a "performance impact" line to the PR template for anything touching the initial route.
  • When a budget is hit, the conversation is "what do we remove to make room," not "raise the limit."

Field notes

  • Never gate PRs on the Lighthouse score. It's a weighted blend that moves between Lighthouse versions; assert on the specific metrics and sizes you care about.
  • Run lab CI against a production build with production compression and caching — a dev server lies about everything.
  • Expect CrUX to lag fixes by up to 28 days. Your own RUM confirms; CrUX is the external scorecard.
  • The best guardrail is cultural: the team that sees field numbers weekly keeps them green.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.