Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(mobile): reuse chat feed rows during streaming #9688

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/9688/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Each assistant-text update rebuilt the loaded mobile activity history and replaced every feed row.

Reuse activity presentation and row wrappers from immutable source objects. Check group membership, live state, expansion flags, and fold labels before reuse. Keep lifecycle collapse, ordering, and pagination behavior. The feed hook now depends on messages, activities, and local feedback instead of the whole thread.

Validation:

  • 116 focused tests, mobile typecheck, lint, and formatting passed.
  • 85 feed comparisons and 3,400 presentation comparisons matched the baseline, including expanded detail and copy callbacks. Cases include same-ID replacements, metadata updates, pagination, lifecycle changes, and fold expansion.
  • The original 10,000-activity audit fixture improved from 20.85 ms to 6.24 ms median feed-build time. It now preserves 2,199 of 2,200 feed rows. The baseline preserved none.

Measurements used Node 24.20.0 with five warmups and 25 samples. These are source-function timings, not device or frame timings. No browser or device testing. No layout, native module, or fingerprint configuration changes.

Refs https://github.com/pingdotgg/t3code/issues/9661.

Created with GPT-6 Astra (preview) in Codex.


Note

Medium Risk Caching ties row identity to object references; incorrect reuse could cause stale UI during streaming, though tests cover regrouping, lifecycle corrections, and expansion state.

Overview Reduces mobile thread feed churn while assistant text streams by reusing stable feed and presentation row objects instead of rebuilding everything on each update.

buildThreadFeed and deriveThreadFeedPresentation now memoize via WeakMaps keyed on immutable inputs: per-message rows, per-activities-array work-log entries, adjacent activity groups, expanded work-group presentation, and turn-fold rows. Unchanged groups are returned when membership and presentation inputs match; only the updated streaming message gets a new object.

groupAdjacentActivities was refactored around a flush pattern that consults the activity-group cache. buildThreadFeed accepts only messages and activities (not the full thread). The composer hook memoizes the feed on those arrays plus local feedback messages, so unrelated thread metadata no longer invalidates the feed.

Tests assert reference stability during streaming, correct regrouping when empty messages appear or pagination prepends history, and presentation behavior for interrupted turns and corrected tool failures.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3b17f380cde95e5aa17f6cf5cb9475bd1d03a6e2. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Reuse chat feed rows during streaming with weak caches in buildThreadFeed

  • Adds weak caches in threadActivity.ts for derived activity entries, message entries, grouped activities, presented activity-group rows, and turn-fold rows, keyed by immutable source objects
  • Reworks groupAdjacentActivities to compare activity sequences against cached groups and reuse unchanged groups, while still creating new groups when the activity sequence changes
  • Updates deriveThreadFeedPresentation and appendPresentedFeedEntry to reuse cached turn-fold and activity-group presentation rows when fold metadata, expansion state, and live-tail state remain equivalent
  • Extracts getThreadFeedActivityEntries and toThreadFeedActivityEntry helpers from buildThreadFeed to support activity-entry caching by activities-array identity
  • Narrows buildThreadFeed input to the messages and activities needed for feed construction, and updates useThreadComposerState to memoize the selected feed from message/activity array references rather than the full thread detail object
  • Risk: useThreadComposerState now depends on array reference stability of messages and activities from the selected thread detail; if those arrays are recreated on unrelated detail updates, the feed will rebuild as before but the perf benefit is lost
Macroscope summarized 3b17f38.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.6 KiB13.6 KiB+17 B (+0.1%)15.1 KiB✅
      CodexThread snapshot wire7.0 KiB7.0 KiB−7 B (−0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.6 KiB+24 B (+0.4%)7.8 KiB✅
      CodexLive turn WebSocket decoded57.0 KiB57.1 KiB+44 B (+0.1%)66.4 KiB✅
      CodexLive turn messages910+1 (+11.1%)21✅
      ClaudeTotal thread wire13.6 KiB13.6 KiB+22 B (+0.2%)15.1 KiB✅
      ClaudeThread snapshot wire7.0 KiB7.0 KiB+3 B (+0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.6 KiB6.6 KiB+19 B (+0.3%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.9 KiB57.9 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages10100 (0.0%)21✅

      Baseline: 27e6cc2 · PR result: 3b17f38 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 113.8 KiB
      • Claude decoded thread snapshot: 114.5 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This production mobile optimization introduces multiple interacting caches that change feed-row identity and rendering reuse during streaming. It is well-scoped and tested, but the cache invalidation and grouping behavior are sufficiently complex to warrant human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Note

      🤖 GPT-6 Astra (preview) responding on behalf of Theo

      I reviewed the cache keys and invalidation paths independently. Activity groups compare every member reference. Presented rows check active-turn state and expansion flags. Fold rows check displayed metadata. The reducer replaces changed inputs instead of mutating them.

      The Node proof matched the previous output for 85 feed cases and 3,400 presentation cases, including resolved detail and copy callbacks. All 116 focused tests and CI pass. Both native fingerprints are unchanged. No browser or device verification was used.

      Macroscope passed correctness but left automatic approval neutral because these caches need review. Theo authorized performance merges after verification. I am confident in this change and will use the normal merge path.

Sign in to join this conversation.