Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(client-runtime): speed up message sync on desktop and mobile #11302

MergedBil0000(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/11302/headmerged by juliusmarminge View on GitHub

Message catch-up applied each event to the UI separately. A 500-delta replay caused 500 message-list updates, keeping desktop and mobile busy while showing "Syncing messages...".

Apply each received batch in order with the existing reducer, then publish and save its final state and cursor once. Single events keep the existing path. Snapshots, reverts, deletes, and pending older-page merges retain their per-event handling. The shared client runtime covers web, desktop, and mobile without changing the protocol, retry policy, or network buffering.

Measured with 500 text deltas through the real thread state machine and message atom, alternating the baseline (7bd7f99e6c) and this branch for nine runs per batch size and discarding the first pair:

Received batch sizeBaseline medianPR medianMessage-list updates
1672.02 ms8.07 ms500 → 32
50050.89 ms1.36 ms500 → 1

These measure client replay processing, not download time or device battery use. Slow links still determine when bytes arrive; no timer waits for a batch to fill.

Validation: 106 focused tests passed across thread sync, atoms, pagination, and the reducer. The regression checks batch sizes 1/16/500, complete ordered text, duplicate delivery, the reconnect cursor, and older-page merging before later deltas. Client-runtime, web, and mobile type checks, targeted lint/format, and the production web build passed.

A real web-client check at 1440 px and 390 px replayed 500 synthetic text deltas, verified the complete text and cleared sync banner, and reported no browser errors. Native mobile is covered by shared-runtime tests and its type check; it was not run on a device.

Model: GPT-6-Astra. Harness: Codex.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at bcda443

      Macroscope's review found this PR approvable — This is a narrowly scoped client-runtime performance improvement that coalesces existing thread synchronization updates while preserving event ordering and exceptional handling. The accompanying tests cover the batching behavior and pagination continuity, with no product-default, schema, security, or deployment changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review Change StackReview Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: a60ba51a-bce4-435c-aac3-882e144999ca

      📥 Commits

      Reviewing files that changed from the base of the PR and between e1c94f703f05b43f2935d09ed1ef882d0ee13ff8 and bcda4432caf2e8992e0afa8aa841da3234f407e3.

      📒 Files selected for processing (3)
      • packages/client-runtime/src/state/threads-atoms.test.ts
      • packages/client-runtime/src/state/threads-pagination.test.ts
      • packages/client-runtime/src/state/threads.ts

      Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.


      📝 Walkthrough

      Walkthrough

      Thread stream consumption now supports batched items. Ordinary batches produce one state update, while complex batches retain per-item handling. Tests cover publication counts, cursor advancement, remounts, and live updates after page merges.

      Changes

      Thread batch processing

      Layer / File(s)Summary
      Batched state reduction
      packages/client-runtime/src/state/threads.ts
      Thread processing reduces ordinary event batches into one state update and preserves per-item handling for complex batches.
      Stream integration and regression coverage
      packages/client-runtime/src/state/threads.ts, packages/client-runtime/src/state/threads-atoms.test.ts, packages/client-runtime/src/state/threads-pagination.test.ts
      Stream consumption selects single-item or batched processing. Tests verify batch publication counts, cursor advancement, remount behavior, and live deltas after page merges.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Refactor

      Suggested reviewers: juliusmarminge

      Sequence Diagram(s)

      sequenceDiagram
        participant ThreadStream
        participant applyItems
        participant ThreadState
        ThreadStream->>applyItems: Deliver a batch of thread items
        applyItems->>ThreadState: Apply one reduced state update
        ThreadState-->>ThreadStream: Advance sequence and synchronization state

      Merge Risk: ⚪ Minimal · up to 8281a

      The batched stream path preserves the complex-event fallback and is covered for publication, cursor, remount, and page-merge behavior. No merge-blocking risk is identified.

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly identifies the primary change: improving message synchronization performance across client platforms.
      Description check✅ PassedThe description explains what changed, why it changed, performance results, scope, validation, and UI verification. It does not use the template headings or checklist, but it provides the required inf…
      ✨ Finishing Touches 💡 1
      🛠️ Fix failing CI checks 💡
      • Create stacked PR
      • Commit on current branch
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge merged thise145c5f

    5. juliusmarminge closed this

Sign in to join this conversation.