TExcelTAD

The Frame Budget

At 60 FPS the whole game, from input to the last pixel, gets 16.67 milliseconds per frame. That number is the frame budget. Everything you add (an enemy, a particle effect, a pathfinding query) spends part of it. When a frame overspends, the player sees a stutter. Performance work in games is budgeting: knowing where the milliseconds go.

Frames per second vs milliseconds

Programmers think in milliseconds per frame, not FPS, because milliseconds add up and FPS doesn't. Budget = 1000 / target FPS:

csharp · try it yourself
using System;

int[] targets = { 30, 60, 90, 120, 144 };
foreach (int fps in targets)
    Console.WriteLine(
quot;{fps,3} FPS -> {1000.0 / fps,6:F2} ms per frame"); Console.WriteLine(); Console.WriteLine("Dropping 10 FPS costs:"); Console.WriteLine(
quot; 60 -> 50 FPS: +{1000.0 / 50 - 1000.0 / 60:F2} ms"); Console.WriteLine(
quot; 30 -> 20 FPS: +{1000.0 / 20 - 1000.0 / 30:F2} ms");
 30 FPS ->  33.33 ms per frame
 60 FPS ->  16.67 ms per frame
 90 FPS ->  11.11 ms per frame
120 FPS ->   8.33 ms per frame
144 FPS ->   6.94 ms per frame

Dropping 10 FPS costs:
  60 -> 50 FPS: +3.33 ms
  30 -> 20 FPS: +16.67 ms

"We lost 10 FPS" means very different things at different frame rates. "The new enemy AI costs 1.2 ms" means the same everywhere, and you can add it to the other costs. VR headsets commonly target 90 Hz or more (11.1 ms), and competitive PC games 144 Hz or more, which leaves very little room.

Splitting the budget

Teams give each system a share of the frame, like a household budget. On many engines the CPU (game logic) and GPU (drawing) work in parallel, each with its own 16.67 ms, so the frame is as slow as the slower of the two. This model adds up CPU costs per system and checks them against the budget:

csharp · try it yourself
using System;
using System.Collections.Generic;

const double budgetMs = 1000.0 / 60;
var cpuCosts = new List<(string System, double Ms)>
{
    ("input + UI", 0.8),
    ("gameplay scripts", 3.1),
    ("AI + pathfinding", 2.4),
    ("physics", 3.6),
    ("animation", 2.2),
    ("audio", 0.6),
    ("render submission", 3.5),
};

double total = 0;
foreach (var (system, ms) in cpuCosts)
{
    total += ms;
    int bar = (int)Math.Round(ms * 4);
    Console.WriteLine(
quot;{system,-18} {ms,4:F1} ms {new string('#', bar)}"); } Console.WriteLine(
quot;{"total",-18} {total,4:F1} ms of {budgetMs:F2} ms ({total / budgetMs:P0})"); Console.WriteLine(total <= budgetMs ? "within budget" :
quot;over budget by {total - budgetMs:F2} ms");
input + UI          0.8 ms ###
gameplay scripts    3.1 ms ############
AI + pathfinding    2.4 ms ##########
physics             3.6 ms ##############
animation           2.2 ms #########
audio               0.6 ms ##
render submission   3.5 ms ##############
total              16.2 ms of 16.67 ms (97 %)
within budget

97% is too close for comfort: the next feature, or a slower player machine, tips it over. Real projects keep headroom, often aiming well under the budget on the target hardware.

Averages lie; spikes hurt

A game that averages 60 FPS can still feel terrible if every few seconds one frame takes 80 ms. Players notice hitches (single long frames) far more than a steady lower frame rate. Look at the slowest frames, not just the average:

csharp · try it yourself
using System;
using System.Linq;

double[] frameMs =
{
    15.8, 16.1, 16.4, 15.9, 16.2, 48.0, 16.0, 15.7, 16.3, 16.1,
    16.0, 15.9, 16.6, 16.2, 15.8, 16.1, 81.5, 16.0, 16.4, 15.9,
};

double avgMs = frameMs.Average();
var sorted = frameMs.OrderBy(ms => ms).ToArray();
double p95 = sorted[(int)Math.Ceiling(0.95 * sorted.Length) - 1];
int hitches = frameMs.Count(ms => ms > 1000.0 / 60 * 2);   // more than two frames' worth

Console.WriteLine(
quot;average: {avgMs:F2} ms ({1000 / avgMs:F1} FPS)"); Console.WriteLine(
quot;95th percentile: {p95:F1} ms"); Console.WriteLine(
quot;worst: {sorted[^1]:F1} ms"); Console.WriteLine(
quot;hitches (> 33.3 ms): {hitches}");
average: 20.95 ms (47.7 FPS)
95th percentile: 48.0 ms
worst: 81.5 ms
hitches (> 33.3 ms): 2

Eighteen of these twenty frames are perfect, yet the two spikes are what players will describe as "it stutters". Typical causes: garbage collection, loading an asset on the main thread, compiling a shader the first time it's used, or a big one-off computation (spawning 200 enemies in one frame).

Measure before you optimize

Guessing where time goes is almost always wrong. Every engine has a profiler that shows the milliseconds per system and per function:

Engine / platform Tools
Unity Profiler window (CPU, GPU, memory, rendering), Frame Debugger, Memory Profiler package
Unreal Unreal Insights, stat unit / stat fps console commands, the GPU Visualizer
Godot the Debugger's Profiler and Monitors tabs, the Visual Profiler
Browser DevTools Performance panel
Native / GPU RenderDoc, PIX (Windows/Xbox), NVIDIA Nsight, Tracy, Superluminal

Profile release builds on the target hardware: editor builds carry extra overhead, and your development PC is usually much faster than the players' laptops and phones.

Cheap habits that keep the budget

  • Don't allocate memory every frame in managed languages (C#): it feeds the garbage collector, which causes spikes later.
  • Don't search the scene for objects every frame; cache references.
  • Spread expensive work over frames (path requests, AI decisions every few frames).
  • Load and prepare assets before they're needed, during loading screens or in the background.

The engine courses cover these per engine; Game Engine Architecture in C++ shows how engines are built to respect the budget.

Test yourself

What is the frame budget at 60 FPS?

  1. 60 ms
  2. 16.67 ms
  3. 6 ms
  4. 33.3 ms

Why do game programmers prefer milliseconds over FPS when discussing costs?

  1. FPS can't be measured
  2. Milliseconds add up linearly; FPS differences mean different costs at different frame rates
  3. Milliseconds are more precise on GPUs
  4. Engines only report milliseconds

A game averages 58 FPS but stutters every few seconds. What should you look at?

  1. Only the average FPS
  2. The slowest frames (percentiles, hitches) in a profiler
  3. The monitor's refresh rate
  4. The number of scripts