A game averages 15 ms per frame, yet players report a visible hitch every few seconds; how do you measure the hitch and track it down?
answer
- averages smooth spikes away
- worst frames, not typical ones
- keep the last seconds recorded
- working or waiting
- move the work out of the frame
basics
~20 sStop trusting averages: track maximum frame time, frames over budget and the 99.9th percentile. Then capture the slow frame itself, with a rolling profiler buffer saved when a frame exceeds a threshold, and compare it with the normal frames before it.
solid answer
~50 sA rare spike disappears in summary statistics: 299 frames at 15 ms and one at 100 ms average about 15.3 ms, and even the 99th percentile is 15 ms, while the maximum and the 99.9th percentile show 100 ms. So I watch a per-frame graph, the maximum and the count of frames over budget. To capture the hitch I keep instrumentation running into a ring buffer covering the last few seconds and save it when a frame exceeds, say, twice the budget. In the saved frames I compare the slow one with its neighbours: which zone grew, on which thread, and whether the thread was working or waiting on I/O, a lock or another job. Periodicity is a clue to timer-driven work. The fix usually moves the work out of the frame: amortise it, run it asynchronously or do it earlier.
code
pseudocode · 10 linesFRAME_BUDGET_MS = 1000 / 60 // about 16.7 ms
HITCH_THRESHOLD_MS = 2 * FRAME_BUDGET_MS // about 33.3 ms
ring = RingBuffer(capacity = 600) // about 10 s of frames at 60 Hz
at the end of each frame:
frame = profiler.collect_frame() // every zone recorded this frame, all threads
ring.push(frame) // the oldest frame drops out when full
if frame.duration_ms > HITCH_THRESHOLD_MS and not cooldown_active():
queue_background_save(ring.snapshot()) // slow frame plus the frames before it
start_cooldown(seconds = 5)go deeper
Recall that an average frame time can look fine while single slow frames stutter, and that a per-frame graph shows them.
Explain why averages and the 99th percentile miss rare spikes, and which metrics, maximum and frames over budget, catch them.
Describe the flight-recorder capture, how to tell a working thread from a waiting one in the slow frame, and how to move the cost out of the frame.
Decide which hitch metrics the team gates on per platform, how play-test telemetry reports them, and what threshold counts as a hitch worth a bug.
## Why the average lies A **hitch** is a single frame, or a few, that take far longer than the budget, long enough for the player to see the image freeze. Hitches are rare by nature, so statistics that summarise many frames hide them. Take about five seconds of play at a 60 Hz target where one frame in 300 hitches: 1. 299 frames take 15 ms and one takes 100 ms. 2. Average frame time: (299 × 15 + 100) / 300 ≈ 15.3 ms, comfortably inside a 16.7 ms budget. 3. 99th percentile: it needs 297 of the 300 frames at or below it, and 299 take 15 ms, so the 99th percentile is 15 ms. 4. 99.9th percentile and maximum: 100 ms. The player sees a freeze every few seconds; the average and even the 99th percentile describe a healthy game. ## Metrics that see hitches | Metric | What it shows | Sees a 1-in-300 hitch? | |---|---|---| | Average frame time | Steady-state cost | No | | Median | The typical frame | No | | 99th percentile | Frequent slow frames | No | | 99.9th percentile | Rare slow frames | Yes, given enough frames | | Maximum | The worst frame | Yes | | Frames over budget per minute | How often players notice | Yes | A **frame-time graph**, one bar per frame, shows hitches immediately as spikes, while a frames-per-second counter that averages over a second smooths them away. On a dedicated server the same applies to tick time: one overrunning tick delays every client in the match. ## Catching the slow frame A hitch every few seconds is hard to capture by pressing a button at the right moment. The standard technique is a **flight recorder**: - keep instrumentation running continuously, writing every frame's zones into a **ring buffer** that holds the last several seconds; - when a frame exceeds a threshold, for example twice the budget, save a snapshot of the buffer, preferably from a background thread so saving does not cause a hitch of its own; - add a cooldown so one bad second does not write dozens of files. The snapshot holds the slow frame and the normal frames before it, which is exactly the comparison needed. In play tests, the same trigger can send the frame time and the largest zones as telemetry. ## Reading the slow frame 1. Compare the slow frame with the normal ones before it: which zone grew, and on which thread? 2. Decide whether the thread was **working** (a zone ran long) or **waiting** (a gap with no zone, or a zone around a lock, a file read or a job). Waits need context-switch tracing or zones around the wait. 3. Look for **periodicity**: a hitch every 3.0 seconds points at something on a timer. 4. Follow the chain: a waiting main thread is waiting for something, such as a worker's job, the GPU or the disk, and that is where the cost lives. ## The usual suspects - A synchronous file load, or a streaming request finished on the main thread. - A first-use cost: a shader or pipeline compiled on demand, a cache filled on first access. - A garbage-collection pause in a managed scripting layer, or a large general-purpose allocation. - Periodic work: an autosave, a telemetry flush, a manager that rebuilds a structure on a timer. - A rare expensive gameplay event: a burst of pathfinding requests, a large spawn wave. - Outside the game: the operating system descheduling the main thread, or page faults on memory touched for the first time. ## Fixing and verifying The work rarely disappears; it moves out of the frame. Typical fixes: - **amortise** it, doing a slice each frame under a fixed time cap; - **move it** to a worker thread or an asynchronous request; - **do it earlier**, during a loading screen, or pre-warm caches; - **avoid it**, for example with pools instead of allocations. Then rerun the same scenario and check the metrics that saw the hitch, the maximum and the frames over budget, not the average, which never saw it.
- The hitch arrives every 3.0 seconds almost exactly. What does that suggest?Something on a timer: an autosave, a telemetry or log flush, a manager that rebuilds a cache on an interval, or a collector triggered by a steady allocation rate. Search for systems with that period; the flight-recorder capture of the slow frame should name the zone directly.
- In the captured hitch, the main thread runs no zone for 40 ms and is not inside the present call. What next?It was waiting, not working: on a file read, a lock, a job it depends on, or descheduled by the operating system. Turn on context-switch tracing or add zones around waits to see what it blocked on, then follow that dependency to the real cost.
- How do you fix a hitch caused by work that genuinely has to happen?Move it out of the critical frame: slice it across frames under a fixed per-frame time cap, run it on a worker or asynchronously, do it during a loading screen, or pre-warm what it builds. Then verify with the maximum frame time, not the average.
- An average frame time under budget means the game plays smoothly.
- The 99th percentile always catches hitches.
- A sampling profile of the whole session shows what caused one hitch.
- A spike with no zone running means the profiler is broken.
- Hitches are always caused by the GPU.