An engine's per-frame job graph takes 14 ms on eight cores while the worker threads sit idle most of the frame: how do you diagnose and shorten it?
answer
- total work against cores
- the longest dependency chain
- one long job nobody can share
- false edges and hidden locks
basics
~20 sCompare total job work divided by cores with the longest dependency chain; a longer chain means a critical-path-bound frame. Shorten it by splitting long chain jobs into parallel batches, cutting false dependencies, prioritising chain jobs and pipelining render preparation.
solid answer
~40 sCapture a per-thread timeline of the frame's jobs and compute two numbers: total work divided by worker count, and the longest chain of dependent jobs. In an illustrative case, 40 ms of work over eight workers is 5 ms, so a 14 ms frame means a **critical path** of about 14 ms: say gameplay 3 ms, physics 4 ms, visibility culling 4 ms and draw preparation 3 ms, each a single job. Then shorten the chain: split culling and draw preparation into **parallel-for** batches; remove **false dependencies**, such as interface draw preparation waiting on 3D culling; give chain jobs **priority** so filler work does not delay them; look for **hidden serialisation** from a shared lock or allocator inside jobs; and **pipeline** render preparation a frame behind simulation if the latency is acceptable.
go deeper
Recall that a frame cannot finish before its longest chain of dependent jobs, however many cores are idle.
Compute both limits, total work over workers and the critical path, and explain why idle workers on a timeline point at a dependency chain.
Lead the fix: split long chain jobs into batches, cut false edges, prioritise chain jobs, find locks that serialise parallel jobs, and pipeline render preparation when latency allows.
Set the rules that keep frames wide as the codebase grows: dependencies declared narrowly, no shared locks in hot jobs, and a timeline review whenever the critical path lengthens.
## Two numbers bound the frame For any job graph run on P workers, two quantities limit the frame: - **Work** W: the sum of every job's duration. P workers cannot finish faster than W / P. - **Span** L, the **critical path**: the longest chain of jobs in which each must wait for the one before. No number of workers runs a chain faster than its own length. So the frame can never be shorter than max(W / P, L). A greedy scheduler, one that never leaves a worker idle while a ready job exists, finishes within W / P + L, so a graph whose span is small next to W / P keeps the cores busy for most of the frame. ## Reading the symptom Take an illustrative frame: 40 ms of job work across eight workers and a measured frame time of 14 ms. - W / P = 40 / 8 = 5 ms, far below 14 ms, so the number of cores is not the limit. - The workers are busy for 40 ms out of 8 x 14 = 112 ms of available core time, about 36%, which is what "idle most of the frame" looks like on a timeline. - The frame is bound by its **critical path**, about 14 ms. A per-thread timeline of job zones shows the chain directly: follow the dependency edges back from the last job of the frame. Here it reads gameplay update 3 ms, then physics step 4 ms, then visibility culling 4 ms, then draw preparation 3 ms, each running as a single job while the other workers wait for it. ## Shortening the chain 1. **Split long jobs.** Visibility culling tests each object independently, so it becomes a parallel-for: 4 ms over eight workers is about 0.5 ms plus scheduling overhead. Draw preparation splits the same way: each batch builds its own list of draws and per-object constants, and a short final job merges and sorts them. 2. **Remove false dependencies.** An edge added "to be safe" serialises jobs that never touch the same data. Draw preparation for a screen-space interface whose draws read nothing that 3D culling writes has no reason to wait for culling; check that every edge on the chain names the data it protects. 3. **Prioritise the chain.** If chain jobs sit in the queue behind non-urgent work such as particle updates or streaming decompression, give them a high-priority queue so a free worker takes them first. 4. **Find hidden serialisation.** A shared lock, a global allocator or a logging call inside parallel jobs makes them run one at a time; on the timeline, jobs with no edges between them form a staircase, each starting as the previous one ends. 5. **Pipeline across frames.** Running culling and draw preparation for frame N while frame N+1's gameplay runs, from double-buffered state, takes them off the simulation's chain at the cost of a frame of latency. After steps 1 and 2 in the scenario, the chain is about 3 + 4 + 0.5 + 0.4 ms, roughly 8 ms plus the merge, and the next limit is the physics step, whose inner parallelism is the physics system's own design. ## Render work as jobs Culling and draw preparation are the CPU side of rendering, and they are classic critical-path material because they sit at the end of the frame and touch every visible object. Scheduling them as jobs, wide parallel-fors fed by the frame's final transforms, is part of the engine's job design. Recording the prepared draws into GPU command buffers on several threads, and the order in which that work is submitted, is a further step that belongs to the rendering side. | Symptom on the timeline | Likely cause | Fix | |---|---|---| | One long job, other workers idle | A loop that was never split | Parallel-for in batches | | A chain of jobs that touch unrelated data | False dependency edges | Remove or narrow the edges | | A ready chain job starts late | Queue order with no priorities | High-priority queue for the chain | | Independent jobs form a staircase | A shared lock or allocator | Per-worker buffers, merged afterwards |
- How do you tell a critical-path-bound frame from one that simply needs more cores?Compare total job work divided by worker count with the frame time. If they are close and the timeline is dense, the frame needs less work or more cores. If the frame is much longer than that figure and workers sit idle, a dependency chain or a hidden lock is the limit, and more cores will not help.
- Why can running more worker threads than cores make a critical-path-bound frame worse?Extra threads do not shorten a chain; they time-slice the same cores, so a chain job can be preempted by filler work and finish later. Oversubscription also adds operating-system context switches and cache churn. Job systems usually keep about one worker per core and control order with priorities instead.
- Idle workers mean the frame needs more worker threads.
- If total work over eight cores is 5 ms, the frame cannot take 14 ms.
- Extra dependency edges are free, so it is safe to add them everywhere.
- Giving a long serial job its own dedicated thread makes the job itself run faster.
- Lowering the slow job's priority lets the rest finish and speeds up the frame.