Skip to content

perf(server): index thread messages so shell builds stop sorting full history - #198

Merged
nullStack65 merged 1 commit into
release/native-0.1.10from
perf/thread-shell-responsive
Nov 24, 2026
Merged

nullStack65 merged 1 commit into
release/native-0.1.10from
perf/thread-shell-responsive

Conversation

@nullStack65

@nullStack65 nullStack65 commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Root cause

The thread shell's latest_visible_text subquery (ProjectionStore.ts, selectShellThreadRows) orders all of a thread's messages by updated_at DESC and filters out idle-compaction messages. Only user messages had a matching partial index, so every shell build used a temp B-tree over the thread's whole history and parsed each user message's JSON. This is the 84ms p50 / 1.3s max statement behind getThreadShell, projectShellItems and sql.transaction on the reader connection (603 calls, 67s total in the trace window).

Fix

Migration 100 adds orchestration_v2_projection_messages_thread_updated_idx (thread_id, updated_at DESC, message_id DESC), and the subquery uses it, so the scan walks in order and stops at the first visible message.

Measured (live DB, read-only, all 486 threads)

  • Before: 6.6s for the real filter across all threads
  • After: 31ms with the index (about 200x)

Tests

  • New 100 migration test asserts the plan uses the index with no temp B-tree.
  • Migrations and ProjectionStore suites pass on the R720, except one pre-existing environment failure (statement.stat, a Node API missing on the R720's system Node).

Not fixed, noted

  • PR sync reactor GitHub calls (up to 3.6s) run in a background sweep outside the DB and request path; only the local persistence write is serialized.
  • Laptop memory pressure (about 200MB free, load 26) likely drives the page-fault stalls and the 700ms sidebar index query, which measures about 90ms warm.
  • PR 180 merged first and took 099, so this migration is 100.

🤖 Generated with Claude Code

Deploy: fleet

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@nullStack65 nullStack65 reopened this Nov 24, 2026
…est visible text

The thread shell's latest_visible_text subquery ordered every message of a thread by
updated_at with no matching index (only user messages had one), so each shell build sorted the
thread's full history and parsed each user message's JSON. Measured on the live database:
6.6s across all 486 threads before, 31ms after. Migration 100.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nullStack65
nullStack65 force-pushed the perf/thread-shell-responsive branch from b24e309 to f1cf01b Compare November 24, 2026 04:33
@nullStack65
nullStack65 merged commit 3da1d5e into release/native-0.1.10 Nov 24, 2026
6 of 11 checks passed
@nullStack65
nullStack65 deleted the perf/thread-shell-responsive branch November 24, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants