Skip to content

12.8 A performance regression bisect

A performance regression can consume headroom gradually and evade functional tests: every test still passes, but TTFT p95 is 15% worse than last month, and nobody can say which of two hundred commits did it. This drill practices a controlled bisect that narrows the change while preserving a stable workload. It is the operational side of Performance regression bisect in Software Engineering.

Concepts from other sections (2)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

A performance regression is a measurement problem first. Unless the machine class, model, request mix, warm-up, and sample count are the same, noise looks like a regression. The drill follows A breaking dependency upgrade, which tried to stop regressions at the gate; this one finds the ones that got through.

The section states the principles and the drill scenario, lists what a correct runbook must cover, and derives the procedure, ending with the model runbook docs/runbooks/PerformanceRegression.md. Try to write the procedure yourself before you read the solution.

Learning objectives

  • Decide whether a latency shift is real, using repeated runs and a threshold fixed in advance.
  • Control the variables that fake or hide a regression.
  • Drive git bisect run with a measuring script, and estimate its cost as about log⁡2n\log_2 n measurements.
  • Confirm the verdict at the boundary commit before reverting or fixing.

Use the same machine class, model, request mix, warmup, and sample count. Set a threshold and rerun the candidate commit before declaring it bad. Set the threshold before measuring, then bisect with a script that measures and decides, so git bisect run finds the first bad revision. Re-measure base, head, and the candidate commit before declaring it bad: one noisy run must not convict a commit.

Inject the seeded regression, run the saved load profile, identify the first bad revision with git bisect, and repeat base/head/candidate measurements.

A runbook for this investigation is complete when it answers five questions:

CaseWhat the runbook must containWhy it matters
Owner and baselinethe metric (for example TTFT p95 or tokens per second), its baseline, and the thresholda decision rule fixed in advance
Controlled workloadthe saved load profile: rate, mix, seed, duration, warm-up, machine classremoves noise sources
Bisectthe good and bad revisions, the measuring script, git bisect runfinds the first bad commit mechanically
Confirmationrepeated base, head, and candidate measurementsrules out a noisy convicting run
Fix and verificationrevert or fix, then the same profile showing the metric back within thresholddone means measured

Is it real? Latency varies between runs. Repeating the same profile several times gives a spread; a regression is a shift larger than that spread, decided by a threshold set before looking.

Remove variables. Use the same machine class, model, request mix, warm-up, and number of samples: each uncontrolled one adds variance that can hide or fake the shift.

Search, do not guess. Between a good and a bad revision, git bisect halves the range each step, so nn commits need about log⁡2n\log_2 n measurements. A script that runs the profile and exits 0 (good) or 1 (bad) lets git bisect run do it unattended.

Confirm the verdict. Re-run base, head, and the first bad commit (and its parent) several times; the shift must reproduce at that boundary.

Fix and prove it. Revert or fix the commit and measure again with the same profile.

The procedure written out as docs/runbooks/PerformanceRegression.md:

# Runbook: performance regression
Owner: the owner of the regressed service.
## Preconditions
- The metric and threshold, for example "TTFT p95 more than 10% above the baseline".
- The saved load profile (loadgen: rate, mix, seed, duration) and machine class.
- A known good and a known bad revision.
## Measure
Run the profile 3 times on base and on head after warm-up; record the
loadgen report's `ttft_ms`, `tpot_ms`, `tokens_per_s`, `error_rate`. A
regression is a shift larger than the run-to-run spread and the threshold.
## Bisect
```bash
git bisect start <bad> <good>
git bisect run ./scripts/perf-check.sh # builds, runs the profile, exits 1 when over threshold
```
## Confirm and fix
Re-measure the first bad commit and its parent 3 times each. Revert or fix,
then run the profile on the fix: the metric must be back within threshold.
Record the commit, the numbers, and the cause.

Setting the threshold first prevents moving the goalposts after seeing the data. git bisect run turns a search over hundreds of commits into about log⁡2n\log_2 n automated measurements. You might be tempted to profile head directly instead, but a profiler shows where time goes now, not what changed. Bisect finds the change; a profile of that one diff then explains it.

The three classic mistakes all let noise make the decision:

PitfallSymptomHow the solution avoids it
Declaring a regression from one runchasing noise; reverting a good commitrepeated runs and a threshold set in advance
Comparing runs on different machines or mixesa shift caused by the environmentthe saved profile and machine class are preconditions
Bisecting by hand with ad hoc judgmentinconsistent verdicts; a wrong first bad commita script with a fixed threshold drives git bisect run

The technique this runbook relies on is Performance regression bisect, and the saved load profile comes from the load generator of An open-loop load generator in AI Engineering. The next drill, A data incident, leaves code changes behind and traces bad data instead. To compare this inject with the adjacent drills and reuse the same containment and verification fields, see the chapter opening.

  • Run-to-run spread: the variation in a metric across repeated runs of the same profile; a regression must exceed it.
  • Saved load profile: a fixed rate, mix, seed, duration, and warm-up that makes runs comparable.
  • git bisect run: git’s binary search over history, driven by a script whose exit code marks each revision good or bad.
  • First bad commit: the earliest revision on which the regression reproduces, confirmed against its parent.
  • A performance regression is a measurement problem first: control machine class, model, request mix, warm-up, and sample count.
  • Fix the metric and threshold before measuring, and call a regression only when the shift exceeds the run-to-run spread.
  • A measuring script that exits 0 or 1 lets git bisect run find the first bad revision in about log⁡2n\log_2 n measurements.
  • Re-measure the candidate and its parent before convicting it, then prove the fix with the same profile.
  1. How many measurements does bisect need for 200 commits?
    AnswerAbout $\log_2 200 \approx 8$, each a full profile run, since each step halves the range.
  2. Why re-measure the candidate and its parent?
    AnswerOne noisy run can misclassify a step of the bisect. Reproducing the shift exactly at that boundary confirms the commit is the cause.
  3. Why fix the request mix and warm-up?
    AnswerBoth change latency on their own; a different mix or a cold cache can produce a shift with no code change at all.