perf(client-runtime): reuse projection entity lookups #25374
main fromrefs/pull/25374/head·opened View on GitHubThe V2 projection reducer scans the same entity array more than once for these update events. A subagent update scans again after restoring omitted bodies, and a provider-turn update can scan three times when it inherits token usage.
Each branch now reuses one located index and prior record for restoration or token usage fallback and replacement. Regression tests cover first-match duplicate IDs, append behavior, body restoration, token usage, and unchanged array entries.
Evidence#
A paired provider-turn replay benchmark applying 200 updates per sample measured:
- 100 loaded turns: 0.265 ms to 0.126 ms mean (2.1x)
- 1,000 loaded turns: 1.899 ms to 0.984 ms mean (1.9x)
Verification#
- Projection reducer tests: 19 passed
- Formatting and lint passed for all changed files
- Both knip passes passed
- Typecheck passed for all seven affected packages
vp run check:changedcould not launch its child checks on Windows (spawn vp ENOENT); I ran those checks directly.
Made with GPT-6-Luna in Codex, running in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
fba2ca1Macroscope's review found this PR approvable — This is a localized client-runtime performance optimization that reuses entity lookups without introducing new capabilities or changing product defaults. Added tests cover the preserved replacement and append semantics, while the remaining changes are benchmark-only or test-only.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 2763bbe
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6c5431aa-bb1c-4af0-8d0c-7aea38af40b7
Commits-
Reviewing files that changed from the base of the PR and between 2763bbeb739e64c181d7800ddb9c1459f678dea4 and fba2ca100cf3683f14385e175157dbb601b6cb76.
Files selected for processing: 3-
packages/client-runtime/src/remotePerformance.bench.tspackages/client-runtime/src/state/orchestrationV2Projection.test.tspackages/client-runtime/src/state/orchestrationV2Projection.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
Walkthrough
-
Projection updates now locate existing entities once and apply changes at the matching index. Subagent updates restore omitted prompt and result fields. Provider-turn updates retain omitted token usage. Tests cover these behaviors, and benchmarks measure repeated provider-turn updates.
Changes: Projection update handling
Priority:Layer / File(s) Summary Indexed upserts and subagent restoration
packages/client-runtime/src/state/orchestrationV2Projection.ts,packages/client-runtime/src/state/orchestrationV2Projection.test.tsThe shared upsert helper inserts or replaces an entity at a supplied index. The subagent update handler reuses its located record to restore omitted prompt and result fields. Tests check restoration and progress updates. Provider-turn updates and benchmark
packages/client-runtime/src/state/orchestrationV2Projection.ts,packages/client-runtime/src/state/orchestrationV2Projection.test.ts,packages/client-runtime/src/remotePerformance.bench.tsProvider-turn updates retain token usage when the event omits it. Tests cover updates to duplicate IDs and appending a turn with supplied usage. Benchmarks replay 200 updates against projections with 100 and 1,000 turns. LowEstimated code review effort: 2 (Simple) | ~12 minutes
Change: Refactor
Possibly related PRs
- pingdotgg/t3code#24647: Adds wire body deduplication and client restoration for subagent bodies, which connects to this PR’s subagent body restoration path.
Suggested labels:
size:MSuggested reviewers:
t3dotgg,juliusmarminge
Merge Risk:
Minimal · up tofba2c-
The projection update appears mergeable after normal checks; no concrete behavior change requiring a fix was identified.
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check The description explains the problem, implementation, benchmark evidence, and verification results. It does not provide the required Scope and approval information, such as a linked issue, maintainer … Add the Scope and approval section. Include the triaged issue or explicit maintainer approval with its discussion reference, or explain why this focused performance fix qualifies without prior approval. Passed checks: 3 passed-
Check name Status Explanation Title check The title clearly and concisely describes the main change: reusing projection entity lookups for performance. 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 explains the problem, implementation, benchmark evidence, and verification results. It does not provide the required Scope and approval information, such as a linked issue, maintainer approval, or justification for a small focused fix.
Resolution
Add the Scope and approval section. Include the triaged issue or explicit maintainer approval with its discussion reference, or explain why this focused performance fix qualifies without prior approval.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Related, separate reducer optimization: #28965 reduces visibility-index construction during run/attempt status updates. It does not change entity lookup/upsert logic or replace this PR. Its focused tests and runnable CI are green, CodeRabbit has no actionable findings, and Maria has been tagged for review.
This PR conflicts with
main. Rebase it or mergemaininto it. If it still conflicts after 7 days with no activity, it will be closed automatically.See the conflict window.
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
Closing: this PR still conflicts with
mainand has had no activity for 7 days since the rebase request.To continue, rebase the branch and open a new PR that links this one. See the conflict window.
github-actions[bot](GitHub profile, opens in a new tab) removed labelsneeds-rebase
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes