Skip to content

perf: reduce timeline row derivation allocations#1

Merged
ronak-guliani merged 1 commit into
mainfrom
perf/timeline-row-derivation
May 19, 2026
Merged

perf: reduce timeline row derivation allocations#1
ronak-guliani merged 1 commit into
mainfrom
perf/timeline-row-derivation

Conversation

@ronak-guliani
Copy link
Copy Markdown
Owner

Summary

  • optimizes deriveMessagesTimelineRows for the chat streaming hot path
  • removes the per-run flatMap message extraction and duration-start Map
  • reuses the main timeline pass to compute duration starts and assistant terminal metadata

Performance audit: 10 opportunities

  1. Chat timeline row derivation allocates intermediate message arrays/maps during streaming updates. Fixed here.
  2. deriveTimelineEntries rebuilds three row arrays and sorts the combined timeline on every chat update; a merge/indexed append path could reduce O(n log n) work.
  3. Chat find rebuilds normalized searchable text for every row whenever timeline rows change, even when the find query is empty.
  4. Chat find match scanning lowercases every row on every query change; storing pre-lowercased row text would cut repeated string work.
  5. Revert checkpoint lookup scans forward through timelineEntries for each user message; a reverse pass could make it linear.
  6. Sidebar project grouping derives logical project keys twice and performs multiple member scans per group.
  7. Sidebar remote environment label de-duping uses indexOf over filtered labels; a Set would avoid O(n^2) behavior.
  8. Sidebar visible thread key construction repeatedly sorts/filter threads per project; per-project memoized sorted buckets could reduce recomputation.
  9. useThreadPlanCatalog scans every environment for every thread id; an indexed selector keyed by thread id would avoid nested scans.
  10. Turn diff checkpoint inference sorts summaries on each active-thread change; preserving server order or caching sorted order would remove repeated sorts.

Validation

  • bun --filter @t3tools/web test MessagesTimeline.logic.test.ts
  • bun fmt
  • bun lint
  • bun typecheck

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added size:M vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels May 19, 2026
@ronak-guliani ronak-guliani merged commit 931422a into main May 19, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 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