Skip to content

perf(web): reuse work log rows during streaming - #8006

Open
Bil0000 wants to merge 1 commit into
pingdotgg:mainfrom
Bil0000:t3code/perf-benchmarks-and-improvements
Open

perf(web): reuse work log rows during streaming#8006
Bil0000 wants to merge 1 commit into
pingdotgg:mainfrom
Bil0000:t3code/perf-benchmarks-and-improvements

Conversation

@Bil0000

@Bil0000 Bil0000 commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Long threads rebuild their full work log for every streamed activity update. That reparsed unchanged activity payloads, cloned every output row, and changed row identities even when the source activities had not changed.

This change caches each immutable activity's derived work-log entry in a WeakMap, keeps collapse metadata private with a symbol, and returns collapsed entries without a second cloning pass. Unchanged activity rows now keep stable identities across append updates.

Benchmark

  • Scenario: derive 20,000 ordered command activities, append one activity, then derive again.
  • Before median: 163.6 ms.
  • After median: 10.1 ms.
  • Median change: 93.8% less time.
  • Before p95: 275.5 ms.
  • After p95: 22.9 ms.
  • The committed regression requires the append update to finish within 100 ms and checks stable entry identity.

Verification

  • pnpm --filter @t3tools/web typecheck
  • vp lint apps/web/src/session-logic.ts apps/web/src/session-logic.test.ts --report-unused-disable-directives
  • vp fmt --check apps/web/src/session-logic.ts apps/web/src/session-logic.test.ts
  • vp test run src/session-logic.test.ts --project unit (77 tests)
  • vp test run src/components/chat/MessagesTimeline.logic.test.ts src/components/chat/MessagesTimeline.test.tsx --project unit (77 tests)

Created with GPT-5.6 in the Codex harness through T3 Code.

Note

Memoize DerivedWorkLogEntry via WeakMap to reuse work log rows during streaming

  • Caches the result of toDerivedWorkLogEntry in a module-level WeakMap keyed by activity object, so repeated derivations for the same activity return the same entry instance
  • Moves the collapse key from the string field collapseKey to a symbol-keyed property [workLogCollapseKey], eliminating the final mapping step in deriveWorkLogEntries that previously stripped internal fields
  • Renames activityKind to sourceActivityKind on DerivedWorkLogEntry; updates all readers in toolLifecycleCollapseMapKey, collapseDerivedWorkLogEntries, shouldCollapseToolLifecycleEntries, and deriveToolLifecycleCollapseKey
  • Adds performance tests in session-logic.test.ts verifying identity reuse for unchanged entries and 20k-entry derivation within 100 ms
  • Behavioral Change: DerivedWorkLogEntry no longer exposes activityKind or collapseKey; any external reader of these fields must switch to sourceActivityKind and [workLogCollapseKey]

Macroscope summarized 647e760.

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 34a76110-cbd4-48ce-9ff5-ceb92ca19156

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Aug 23, 2026
@macroscopeapp

macroscopeapp Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Skipped

Macroscope did not run approvability analysis for this PR. Macroscope could not determine whether this PR modifies its approvability configuration, so the PR was not approved automatically. A PR that may change the rules that govern approval is never approved automatically.

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

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant