#2973·gstack

perf(browse): avoid full activity-ring copies on caught-up and bounded history reads?

Author: kvnlooCreated Sep 25, 2026Updated Sep 25, 2026

Would a narrow activity-read optimization be useful, while deliberately leaving the existing cursor and limit contracts unchanged?

At 730a1017d1a15a8c0c214b820b3865b6e2a32547, getActivityAfter copies the whole ring before discovering that a cursor is already caught up, and getActivityHistory(50) copies all entries before slicing. The experiment adds a caught-up fast path using the newest monotonically assigned ID and reuses CircularBuffer.last(limit) for positive integer history limits. Zero, negative, fractional and non-finite limits keep the old fallback.

Native fork validation on Ubuntu 24.04 / Bun 1.4.0:

  • Differential checks cover empty, full and wrapped rings; stale/current/future cursors; unusual limits; emitted entries and subscriber delivery.
  • A separate method-call probe confirms one full-ring copy -> zero for both caught-up reads and history-of-50 reads. That instrumentation is removed before timing.
  • All 18 existing activity tests pass before and after, including privacy filtering and subscription behavior.

The single-run history-of-50 microbenchmark was 4.4985 microseconds -> 0.4348 microseconds per call over alternating ABBA/BAAB batches. Gap replay and legacy zero-limit controls were essentially unchanged. These are synthetic module timings, not browser/UI, HTTP or SSE latency measurements; the caught-up path is intentionally not advertised as a large system-wide speedup.

Native CI and logs · raw timing/copy evidence and candidate patch · reproducible probe

Would you prefer this compatibility-preserving change on its own, with clarification of limit=0 and other edge cases kept separate? No event dropping/coalescing, scheduling, privacy policy or public API additions are proposed.

AI-assisted investigation, candidate and test preparation. Full free-suite, live browser/server integration and other-platform validation remain gates before a production PR; the production edit currently exists only in the disposable CI checkout.