Skip to content

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

Closed as not planned

Description

@kvnloo

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.

Activity

  1. kvnloo commented on Sep 25, 2026

    @kvnloo
    Author

    Full-suite comparison update: the saved test receipts are not green, so I am not opening a performance PR on that basis.

    On the same upstream base 730a1017, both the unmodified baseline and the activity candidate recorded full-free-exit.txt = 1. Both timed out in ios-qa/scripts/gen-accessors.test.ts at the @Observable Swift typecheck; baseline additionally timed out in test/ios-qa-regen.test.ts. The activity/server checks passed 86 tests in each variant, and the candidate's 2,746 semantic comparisons preserved output.

    Baseline receipt · candidate receipt

    A job-summary response reported success, but that conflicts with the raw exit files and failure logs; the failure receipts take precedence. I have not established why those summaries disagreed.

    I started a separate fork-only diagnostic that repeats the two unchanged Swift fixtures independently on baseline and candidate, records the toolchain and every exit code, and retains the original test/subprocess time limits. This will distinguish isolated behavior from the full-suite result; it does not yet establish contention as the cause. No test has been skipped or weakened to obtain a pass.

    AI-assisted investigation. No whole-system speedup or completed full acceptance is claimed.

  2. capy-ai commented on Oct 11, 2026

    @capy-ai
    Contributor

    Thanks @kvnloo for the idea. In the Oct 11 triage we grouped the open feature requests by theme so related asks get built together instead of one at a time. This one is part of the Browser and mobile QA theme in TODOS.md (https://github.com/garrytan/gstack/blob/50d020ad9/TODOS.md#L54-L69). Closing it here so the open list stays actionable; it isn't rejected, and the theme credits every linked reporter when it's picked up.

  3. added
    parked
    on Oct 25, 2026
  4. capy-ai commented on Oct 25, 2026

    @capy-ai
    Contributor

    Reopened under the parked label: this is tracked in the Browser and mobile QA theme in TODOS.md (https://github.com/garrytan/gstack/blob/main/TODOS.md#p3-feature-themes-from-the-wave-9-triage-filed-2026-10-11), and what fixes it is the next browser-engine wave, which takes the theme as a whole. Closed-but-tracked read as closed, so parked issues now stay open until they ship, are duplicates, or are declined (https://github.com/garrytan/gstack/blob/main/docs/triage.md).

  5. added
    S3
    on Oct 31, 2026
  6. capy-ai commented on Oct 31, 2026

    @capy-ai
    Contributor

    Measured this on current main (3bfe566) before deciding whether to change it.

    With a full 1,000-entry ring (BUFFER_CAPACITY), on a 4-core Linux box with Bun 1.4.4, three rounds of 20,000 calls each:

    • caught-up getActivityAfter(newestId): 7.4 to 7.9 µs per call
    • getActivityHistory(50): 4.0 to 5.6 µs per call
    • for scale, JSON.stringify of a single activity entry: 4.7 to 6.3 µs

    Both functions run once per request, not per event: getActivityAfter is the SSE stream's initial replay when the side panel connects or reconnects, and getActivityHistory serves /activity/history, which then serializes up to 50 entries (roughly 50x the copy cost). Live events go through subscribe and never touch the copy. So the full-ring copy is a few microseconds on a path that already pays far more for serialization and HTTP, and no user can see it.

    We're not taking this change: there is no user-visible cost to remove, and the fast path adds a second way to compute the same answer. Thanks for the careful write-up and the differential checks. If you see a real workload where these reads show up in a profile, post the profile here and we'll look again.

  7. capy-ai commented on Oct 31, 2026

    @capy-ai
    Contributor

    Thanks again for the careful write-up, @kvnloo. As measured above, the copy costs a few microseconds and no user can see it, so we're closing this as not planned. If you have a profile showing it matters, post it and we'll take another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S3parked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions