Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(client-runtime): reuse projection entity lookups #25374

ClosedNarayan201120(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/25374/headopened View on GitHub

The 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:changed could 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

    2. Approvability

      Verdict: Approved at fba2ca1

      Macroscope'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).
    3. Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      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.ts
      • packages/client-runtime/src/state/orchestrationV2Projection.test.ts
      • packages/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

      Layer / File(s)Summary
      Indexed upserts and subagent restoration
      packages/client-runtime/src/state/orchestrationV2Projection.ts, packages/client-runtime/src/state/orchestrationV2Projection.test.ts
      The 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.ts
      Provider-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.
      Priority: Low

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

      Suggested reviewers: t3dotgg, juliusmarminge

      Merge Risk: Minimal · up to fba2c

      The projection update appears mergeable after normal checks; no concrete behavior change requiring a fix was identified.

      Pre-merge checks: Passed 3 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Description checkWarningThe 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 Passed checks: 3 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: reusing projection entity lookups for performance.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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
      Comment `@coderabbitai help` to get the list of available commands.
    4. 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.

    5. This PR conflicts with main. Rebase it or merge main into it. If it still conflicts after 7 days with no activity, it will be closed automatically.

      See the conflict window.

    6. Closing: this PR still conflicts with main and 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.

Sign in to join this conversation.