diff --git a/docs/design/session-framework/implementation.md b/docs/design/session-framework/implementation.md index f45c012..efcf767 100644 --- a/docs/design/session-framework/implementation.md +++ b/docs/design/session-framework/implementation.md @@ -441,6 +441,44 @@ B1, N1 and N3. - Against it, the legacy loop spends about 0.7 ms per frame outside the ticks. - The report `claude-task-01` has the per-phase table and what would close the rest. +### PERF-01 — The session runtime's per-frame cost (port slice) + +**2026-09-30: built** on `port/perf-01` (off `port/task-01`, with `main` v0.6.7 merged) and +awaiting review. Goal: cutover must not slow the live stream. TASK-01's fix round left the +in-process session about 4.7 ms a frame above its brain, against 0.7 ms for everything the legacy +loop does outside its ticks. No behaviour changes: the parity runs are identical frame by frame, +in-process and process, and the compatibility string is unchanged. + +- **The local lane** (the big one; ipc-v1 section 1 and bus-v1 section 12, amended 2026-09-30). + An in-process worker's shell is offered to the coordinator directly (`worker::LocalLane`, + `launcher::Via::Local`, `WorkerRef::local`); `rpc::send` takes it for every endpoint method. + The request still goes through the shell's admission, deduplication, arrival order and + endpoint, and the reply is the same outcome. Handler media over the lane are in-memory + artifacts (`flybus::Artifact::in_memory`, `HandlerCtx::seal`): no store file, no seal copy, + no retain or open round trip. A bus call or a publication carries a sealed copy + (`rpc::promote`), begun while the task and the commits run. Process mode is untouched. + `FLY_SESSION_LOCAL_LANE=0` runs in-process over the bus. Every synthetic transport test also + runs over the lane. +- **The spike bitset** is the union of the kernel's per-tick spike lists, gathered while Prepare + ticks (`LifNetwork::tick_spikes`), instead of a 139,255-neuron scan in Commit. Same bits, + proved by `flybrain-core/tests/tick_spikes.rs` and compared every frame by the parity runs. +- **The session topic** gets a committed snapshot every 60th boundary in a service session (and + at every boundary with events or boundary actions), not every other one. Nothing in the + release subscribes; the stream is the legacy feed. +- Small ones: a single dispatch job is called in place, the shell moves the reply result + instead of cloning it, `digest_views` and `media_bytes` as SERVE-01 has them, and profiling + spans for the shell, the lane, each handler and the brain's own phase clock. +- **Tried and dropped**: publishing without waiting for the router (a deferred publish) and any + other overlap with Prepare. On the release CPU the sweep owns every core of the cpuset, and + work beside the ticks slowed them by up to 30% in one run. Spikes only at the feed rate + (an AGENT-01 amendment) was not needed once the bitset cost nothing. +- **Measured** (`tests/speed_ab.rs` with `FLY_PERF_ARMS`, `FLY_PERF_SERVICE`, `FLY_PERF_WORKERS`; + the report `claude-perf-01` has the tables): on the release host's CPU model, pinned to the + release cpuset's size, the in-process session's cost outside the brain fell from about 9.3 ms + to about 3.5 ms a frame. The legacy loop's is about 1.3 ms. What is left is mostly the per-frame + memory image (0.37 ms, 65,536 shim reads), the three domain calls' JSON, digests and cache + (about 0.5 ms together) and the task's evaluation, which the legacy loop does too. + ### STATE-01 — Coherent all-participant checkpoint/recovery **Depends on:** SESSION-02, MEDIA-01; validate with fake agents first, then AGENT-01/ENV-01. diff --git a/docs/design/session-framework/legacy-gameboy-v1.md b/docs/design/session-framework/legacy-gameboy-v1.md index 281079c..a9a5988 100644 --- a/docs/design/session-framework/legacy-gameboy-v1.md +++ b/docs/design/session-framework/legacy-gameboy-v1.md @@ -415,6 +415,31 @@ interface LegacyGameboyComposition { for publication, traces and descriptor revisions, not a restore gate. This matches today's behaviour, where a decoder change does not refuse a checkpoint. +**Amendment, 2026-09-30 (PERF-01): the in-process release configuration.** Nothing in the +declaration, the digest or the compatibility string changes; these are execution choices of the +composition as `fly-legacy-session` builds it, recorded here because the shadow compares the +behaviour they must not change. + +- *In-process participants are called over the local lane* ([session RPCs](ipc-v1.md) section 1, + 2026-09-30): the frame, the memory image, the audio chunk and the spike bitset are in-memory + artifacts, handed over without a store file. Process mode is unchanged and still goes through + the router. `FLY_SESSION_LOCAL_LANE=0` puts an in-process session back on the bus. +- *`telemetry.spikes` is unchanged*: one bitset per transition, bit `i` set when neuron `i` + spiked in `[transition start, brain time)`, the legacy layout. The agent now builds it as the + union of the kernel's per-tick spike lists while Prepare ticks (`LifNetwork::tick_spikes`) + instead of scanning 139,255 last-spike times in Commit; the two are equal by construction and + by test, and the parity runs compare the bitset every frame. The AGENT-01 alternative -- attach + it only at the feed rate -- was not needed and was not made. +- *Committed snapshots on the session topic*: a service session publishes every 60th boundary and + every boundary with task events or boundary actions (it was every other boundary). The live + presentation is the legacy feed, which the service host builds from the committed boundary at + 30 Hz; nothing in the release subscribes to the session topic, and each publication seals a + store copy of the frame and the audio chunk. Every publication is still of a committed + boundary and still attaches the media it names (publishing-v1 section 3). +- *Nothing runs beside the brain's ticks.* On the release CPU with the sweep owning every core of + the flysim cpuset, work overlapping Prepare (a publication left in flight, for instance) slowed + the ticks by up to a third, so the coordinator finishes each boundary before the next Prepare. + ## 13. Machine-readable parts | Where | What |