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).

Not yet: a synthetic probe for routes with no traffic (a client-written label would let anyone hide requests; it needs an admin-only door first), route-hour stats in the terminal (findings reach it as issues; the MCP system kind: routes reads the live routes), browser timings, the board page, release before/after.

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.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs