Performance watcher (#7559)
src/perf/ keeps a capped in-memory record of real requests per route pattern (total, each Server-Timing phase, signed in or out; no paths, ids or queries). budgets.ts holds the budgets in words with the number beside them. Once a minute duty.ts files one issue per route and phase in the forge's repo when p95 has been over budget for 15 min with 20+ real requests; the finding names the slowest phase, its share and the cache hit rate. git.ts keeps the same record for every git process the forge spawns (git/env.ts, git/local.ts), keyed git <subcommand> from a fixed list (never an argument, path or ref; anything else is git other), timed from before the spawn gate so a queue counts; a subcommand whose p95 passes its budget the same way (250 ms; 10 s for the pack-moving ones: clone, fetch, push, gc, repack, pack-objects and the like) files one issue naming it, its count, p50 and p95. loop.ts names the routes running across an event-loop stall in the loop log line; nothing is kept beyond that line. loop_worst.ts keeps the worst event-loop lag of the last 10 s (ten one-second slots fed by the 50 ms sampler) and every response's Server-Timing names it as lag;dur; /healthz answers it as loopLagMs to Accept: application/json, so a slow time to first byte with a small app;dur reads as a stall outside the handler.
history.ts (#11477): every tick the duty folds the record's new samples into an in-memory ledger under the hour each sample happened in (so 10:50 traffic is never stamped 11:00) and upserts one row per route pattern (route, hour, n, p50, p95) into route_hour, so a row is the hour's p50 and p95, not the last 15 minutes'. At most 5,000 samples per route and hour are kept (past it the row stands on the first), at most 200 routes (the busiest) and 168 hours; older rows go in the same write. A restart starts an empty ledger: an empty record writes nothing, and a row is never replaced by one with fewer requests, so the hours before the restart keep the fuller row. Admins read them at GET /api/v1/telemetry/routes?hours=N (1 to 168, default 24; else 400); each row says synthetic.
probe.ts (#16066): from minute 50 of each hour, the duty asks once for each budgeted GET route that had no real request that hour and has a sample address in budgets.ts (/, /boards, /explore, /api/v1/health). The door is Servers.probe, a function the booting process hands the duty: it answers through the routes without the listener, so nothing in a request names it (no header, query or address a client can set) and it is counted in no record. The answer's time becomes one route_hour row with synthetic set (n 1); it never replaces a row of real traffic, a later real write replaces it, and it never enters the record evaluate reads, so a probe cannot file a finding. A route with parameters (/:owner/:name) or a phase budget (/explore#read) is not probed; the admin read lists them as notProbed with why. Nothing is probed while FORGE_CHECK is set, and a probe answered 4xx or 5xx leaves no row. The probe is anonymous, the same as a visitor's; every probed route is public, so it needs no admin identity, only that the server alone can ask.
The last 24 hours read in the terminal's System screen (admin who is a person; the five slowest p95 first, with n, p50, p95 and the budget) and as the admin-only route_hour boards source (route, hour, n, p50, p95; slowestRoutes is one indexed query).
/changelog shows admins, under a heading, a plain row per release of the last seven days saying which routes got faster or slower after it (release_delta.ts compares the p95 of the 24 hours either side; release_speed.ts reads the rows). The terminal's changelog screen (src/tui/screens/changelog.ts) puts the same line in the release's own row, for an admin who is a person.
Not yet: browser timings.
Sampling the main thread: FORGE_PROFILE=1 (#12455)
GET /api/v1/admin/profile?seconds=N samples what the main thread is doing
(src/perf/sample.ts). Bun cannot stop the sampling profiler once started, and
its traces piled up until the forge ran out of memory, so a forge that serves
people answers an admin 403 with code refused and the sentence
"Profiling is off on a forge that serves people…". To allow it, start the
process with FORGE_PROFILE=1 — meant for the stage rig, not production. Once
a sample has run the profiler stays attached until the process restarts, and
its traces are drained and discarded every two seconds by the profiler-drain
job; a window being sampled keeps its traces until it ends.
Release before/after (#16067)
release_delta.ts compares each route's p95 in route_hour over the 24 hours before a release with the 24 hours after it (the release's own hour is left out; a day's p95 is the request-weighted mean of its hours', an estimate). A route that moved 20% or more with 20+ requests on both sides is named, at most three faster and three slower. /changelog shows one line per release of the last seven days ("Faster: /x (120 → 80 ms). Slower: /y (40 → 70 ms).") to admins only; a release with nothing moved, or older than the 168 hours kept, shows nothing.
The 1-4 s pauses labelled jobs egress-idle (#16113)
Measured with scripts/pause-rig.ts (a measurement rig, not run by CI or bun test; 420 egress servers with four connections each, a retained heap, a 10 ms loop-lag probe; run under bun --cpu-prof). The pause is neither a collection nor the sweep's loop: it is heapSize() (bun:jsc), called twice inside every during() by the allocation tally (src/perf/job_alloc.ts). On Bun 1.4.4 it is not constant time; it costs about 17 ms per GiB of heap, per call:
| retained heap | heapSize() | one during() |
|---|---|---|
| 250 MiB | 2 ms | 4 ms |
| 1 GiB | 13 ms | 24 ms |
| 4 GiB | 60 ms | 123 ms |
| 7.6 GiB | 132 ms | 263 ms |
In the CPU profile of 420 cells on a 1 GiB heap, heapSize held the thread for 47.9 s of 57 s; the sweep's own loop (egress.ts line 1006) took 67 ms, during 19 ms. A full collection of the same heap took 1.1 to 1.6 s and, being inferred from a heap that fell, was the "no collection seen" the stall line reported as absent. So the sweep's loop is a few lines, as suspected, and what it paid was the tally's size read, per timer, per slice: any job on a big heap, 420 sweeps worst. Each slice that ran across a stall was named, so egress-idle took the label. Not reproduced: production's own 8 GiB shape; the rig's heap is millions of small objects, so absolute milliseconds will differ, the growth with heap size will not.
Fixed by bounding the cost, not removing the count: the tally spends at most 0.5% of wall time (and a first 50 ms) reading the heap's size and runs the remaining slices uncounted. The memory allocated by jobs line is therefore a sample on a big heap, and says so: the tally counts the slices it did not read and the line ends (sampled: N slices not counted), left off when N is 0. With the change the rig's 420 cells at 1 GiB showed only collector-sized pauses (0.3 to 0.6 s), none of the 20 s ones. Test: test/job-alloc.test.ts. The per-memory-minute heapSize() calls in memory_watch.ts are once a minute and stay.