GeezerVison is showing github.com — perf(web): reuse timeline entries for unchanged turn items by hieu-lee · Pull Request #26693 · pingdotgg/t3code
Conversation
Problem
deriveTimelineEntriesFromVisibleTurnItems has an incremental path for streamed assistant text and appends. Any other item change, such as a tool going from running to completed, command output updating, or a title change, falls back to rebuilding every entry. That rebuild formats timestamps, builds tool presentations, and runs mcpAppFromToolItem for every completed dynamic tool. The last step re-parses each output, and JSON.parse throws on prose. On a 600-turn thread (5,400 items) each such update cost ~11 ms before row derivation even started.
Fix
Per-row entry construction moves into a closure, unchanged. A module-level WeakMap keyed by the projected turn item reuses the previous entry when the row object is the same:
- Skip checks and
resolveAttempt still run on every call. A cached entry is used only when its attempt is the same object as the one just resolved.
- Rows whose entry reads other inputs are never cached: proposed plans (status comes from
plans) and messages with attachments (preview URLs come from attachmentUrlById).
- Unchanged rows keep their entry identity across updates, which later identity checks (stable rows, superseded reasoning) already rely on.
Output is unchanged.
Measurements
Harness: the real deriveTimelineEntriesFromVisibleTurnItems, bundled with esbuild and run in plain Node 24.18 (Apple Silicon). Synthetic thread: N turns, each with 1 user message, 7 items (command, read_file dynamic tool, intermediate assistant message), and a final assistant message, with the last turn live. Each timed call replaces the last row with an updated copy, like a live tool update, and derives again. Old and new builds ran interleaved, 5 process runs each. Each run: warmup, then 30 timed calls (per-run median), plus allocation from the heapUsed delta around one call, after gc() with --max-semi-space-size=1024, counting only samples with no GC. The table shows the median across runs.
| Thread |
Before |
After |
Alloc before |
Alloc after |
| 100 turns (900 items) |
1.84 ms |
0.046 ms |
1.56 MB |
0.18 MB |
| 600 turns (5,400 items) |
11.0 ms |
0.29 ms |
9.4 MB |
1.1 MB |
| 1,200 turns (10,800 items) |
22.4 ms |
0.61 ms |
18.8 MB |
2.4 MB |
Cold derive, where every row is new (thread open, or a snapshot after reconnect): 10.9 ms → 12.6 ms at 600 turns. That one-time cost is the WeakMap inserts; every later update then hits the cache.
What limits the new number: the per-row skip checks, resolveAttempt, the WeakMap lookup, and building the output array and the answer and message-id sets. All of these are linear and cheap.
Benchmark harness
import * as NEW from "~/session-logic";
import * as OLD from "~/__orig_session-logic"; // copy of main
import { makeLongThread } from "./timeline-fixture"; // N turns x (user, 7 tool/assistant items, final assistant)
const { visibleTurnItems } = makeLongThread(turns, 7, { liveLast: true });
const impl = process.env.IMPL === "old" ? OLD : NEW;
let rows = visibleTurnItems, n = 0;
measure("deriveTimelineEntries(tool update)", () => {
const last = rows.at(-1)!;
rows = [...rows.slice(0, -1), { ...last, item: { ...last.item, title: `t${n++}` } }];
return impl.deriveTimelineEntriesFromVisibleTurnItems({ visibleTurnItems: rows, optimisticMessages: [] });
});
// measure(): 10 warmup calls, 30 timed calls with performance.now() (median),
// then 5x { gc(); h0 = heapUsed; fn(); h1 = heapUsed } keeping samples with no GC event.
// Bundled: esbuild --bundle --platform=node --alias:~=./src; run: node --expose-gc --max-semi-space-size=1024
Validation
vp run check:changed: format, lint, knip, typecheck, and tests pass.
session-logic.test.ts, session-logic.runtime-diagnostics.test.ts, MessagesTimeline.logic.test.ts, MessagesTimeline.active-tools.test.ts, and ChatView.logic.test.ts: 178 tests pass.
- Differential fuzz (not committed): old and new output, compared as JSON over 32,000 derives. Each random case ran 4 derives in sequence on the same rows. Between steps, some rows were replaced with modified copies, items were appended, and
attempts, nodes, plans, and attachmentUrlById were each kept or regenerated, so the cache is hit while the context changes. Inputs mixed messages with and without attachments, proposed plans, notifications, checkpoints, async answers, dynamic tools, attempts, and nodes. Zero differences. As a sensitivity check, a deliberately broken guard (also caching plans and attachment messages) makes the fuzz fail on the first case.
- No timeline entry is mutated after derivation. I grepped
apps/web/src, and deriveTimelineEntriesFromVisibleTurnItemsWithState already reuses message entries by identity.
Not checked: I did not profile in a real browser; the numbers above come from Node.
Authored with Claude Opus 5.5 via the Claude Code harness in T3 Code.
🤖 Generated with Claude Code
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Any non-text item change (tool status, command output) re-derived every
timeline entry, re-formatting timestamps and re-parsing every dynamic tool
output: ~11 ms per update on a 5,400-item thread. Entries are now cached per
projected turn item and reused while the item and its resolved attempt are
unchanged (~0.3 ms, 8x less allocation). Plans and messages with attachments
read other inputs and stay uncached.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
coderabbitai
Bot
commented
Oct 28, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Walkthrough
-
The timeline derivation function now builds entries through a per-row helper and caches eligible entries by projected-row identity. It reuses a cached entry only when the resolved attempt is unchanged.
Changes: Timeline entry derivation
| Layer / File(s) |
Summary |
Build and reuse timeline entries apps/web/src/session-logic.ts |
entryForRow returns entries for the existing row types. The outer loop retains the row filters, tracks committed message IDs, and appends entries. A WeakMap caches entries for eligible rows while their resolved attempt is unchanged. Proposed-plan rows and rows with attachments are excluded from caching. |
Priority: Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Refactor
Suggested reviewers: yash-singh1, t3dotgg
Merge Risk: Low · up to ffca4
-
An in-place tool payload change could leave its timeline presentation stale. The change is mergeable with that bounded uncertainty.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title clearly and concisely describes the main change: reusing timeline entries for unchanged turn items to improve web performance. |
| Description check |
 |
The description clearly explains the problem, implementation, performance measurements, validation results, limitations, and agent attribution. It uses “Fix” and “Validation” instead of the template’s… |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
Check skipped because no linked issues were found for this pull request. |
Full details: Description check
-
Explanation
The description clearly explains the problem, implementation, performance measurements, validation results, limitations, and agent attribution. It uses “Fix” and “Validation” instead of the template’s “Change” and “Verification” headings, and it omits the required “Scope and approval” section or an explanation for an approval exemption. The core information is otherwise complete enough to pass.
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
@juliusmarminge ready for review. Tool and status updates no longer rebuild every timeline entry: 5.4k items 11.0 ms to 0.29 ms, 9.4 MB to 1.1 MB. Stacks with #26688 (a live tool update on a 5.4k-entry thread drops from about 100 ms to about 6 ms of derive work). Related to #26018. The first derive on open or reconnect is slightly slower (10.9 to 12.6 ms) because it fills the cache. CI workflows on this fork PR show action_required, so they are waiting on a maintainer to approve the run. CodeRabbit and Macroscope are done with no open findings.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 28, 2026
|
Closing as superseded by #26727, which landed the same optimisation on main: a changed tool or work item is re-derived in place (12 ms to 0.3 ms, matching the 0.29 ms this PR measured) instead of rebuilding every entry. The two overlap in reuseTimelineEntries, so keeping this would only add a second cache.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
size:M
30-99 changed lines (additions + deletions).
vouch:unvouched
Author is not yet trusted in the VOUCHED list.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|