# Routine scheduler benchmark

Local macOS arm64 run, 2026-09-16, Zig 0.16.0 ReleaseFast. Reproduce from
`src/hikari` with `zig build routines-bench -Dgame-src=<absolute-game-src>
-Doptimize=fast` (one command). This is a synthetic headless workload;
it excludes gameplay logic, rendering, physics, and editor lifecycle costs.

Each cohort reserves 64 KiB per fiber, warms all fibers, then measures 240 ticks.
The ready workload increments a counter and calls `nextTick`; sleeping fibers
wait 1,000 simulation seconds. The tick budget is **1,024 resumptions**, not the
entire cohort. Timings include scheduler and these minimal function bodies.

| Population | Configured stacks | Reserve ms | Sleeping mean / p95 µs | Ready mean / p95 µs |
|---:|---:|---:|---:|---:|
| 1,000 | 62.5 MiB | 1.14 | 0.02 / 0.04 | 88.45 / 135.58 |
| 10,000 | 625 MiB | 8.35 | 0.02 / 0.04 | 182.34 / 287.83 |
| 100,000 | 6,250 MiB | 136.56 | 0.02 / 0.04 | 413.10 / 697.54 |

Stack budgets exclude metadata, guard pages, and platform rounding and are not
measurements of resident RAM. The near-zero sleeping figures describe the empty
ready-path check at this clock's measurement resolution. They do not include
initial stack reservation, first-resume page faults, or waking all sleepers.
A ready population of 100,000 takes about 98 ticks per service round at this
budget. Changing the budget trades latency against frame CPU cost.

Cancelling and draining all 100,000 sleepers took **147.53 ms total across 98
passes**; the ready cohort took **48.26 ms across 98 passes**. These are total
cleanup costs, not single-frame costs. Play Stop stages routine cleanup before
retiring the owning game subsystem and actor storage. Reserve/admission and
cancellation-marking costs are not preemptible; configure capacity during setup.

The harness fails on capacity/admission errors, lost cleanup, sleeping work
executing early, exceeded resumption budgets, or failure to service the stable
ready cohort within the measurement window. These numbers are one local run,
not platform guarantees; Windows runtime performance has not been measured here.
