Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(client): reduce remote request and message sync overhead #11029

MergedBil0000(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/11029/headmerged by juliusmarminge View on GitHub

Remote connection setup and snapshot requests rebuild handlers for the entire HTTP API, even when they need one group. Each streamed message update also scans the message list twice. Both costs run in the shared client runtime used by web, desktop, and mobile.

This PR makes two small changes:

  • Use the existing Effect HttpApiClient.group to build only the handlers needed by authentication, environment metadata, and snapshot requests. Keep request validation, transport context, authorization refresh, and error mapping in place.
  • Apply message updates in one native array pass. Preserve message order, unchanged object references, streamed/final text handling, and attachment updates.

Three focused commits separate HTTP processing, message updates, and the benchmark. No new dependency, response cache, wire format, or connection policy.

Benchmarks

Actual before/after client functions; milliseconds, lower is better. The HTTP transport returns fixture responses in memory, so these measure client processing, including response validation, rather than server or network latency. The message cases apply 200 deltas to the last message in the loaded history through the production reducer.

WorkloadChrome beforeChrome afterLess timeNode before → after
Read connection descriptor6.1860.57090.8%9.489 → 0.325
Issue WebSocket ticket5.7381.99265.3%6.490 → 1.830
Load a snapshot with 100 messages11.6344.64260.1%7.701 → 1.871
Apply 200 deltas, 100 loaded messages0.9820.60438.5%0.363 → 0.244
Apply 200 deltas, 1,000 loaded messages3.5221.86847.0%3.772 → 2.122

Chrome values are medians of nine alternating before/after batches, 50 operations per batch, after 100 warm-up operations per version. Node values are Vitest sample medians with a 1-second warm-up and 1.5-second measurement per case. Timing varied substantially between runs; these results do not establish end-to-end latency. Network bytes, GPU load, memory use, and battery drain were not measured.

The benchmark at packages/client-runtime/src/remotePerformance.bench.ts runs the five Node cases. To reproduce, copy that file to the baseline (b7b3ef1e6fcb5c22a9790d2578fe8af7ce396835) and run from packages/client-runtime:

# Baseline checkout, with the benchmark copied in
vp test bench src/remotePerformance.bench.ts --run --outputJson /tmp/t3-remote-before.json

# PR checkout
vp test bench src/remotePerformance.bench.ts --run --compare /tmp/t3-remote-before.json --outputJson /tmp/t3-remote-after.json

Verification

  • 192 focused tests passed across authorization, connection resolution, RPC sessions, HTTP error handling, message updates, shell sync, thread sync, and pagination. Added checks for malformed responses and updates at each message position without input mutation.
  • 10,000 deterministic comparisons of the old and new message reducer produced identical outputs, including duplicate IDs, streaming/final text, attachments, and unchanged message references.
  • Client-runtime and web typechecks, targeted lint/format checks, and the production web build passed.
  • Verified remote pairing, saved message loading, switching away and back without another snapshot request, and reconnecting after a remote server restart. The client reconnected, received the synchronization marker, preserved the messages, and resumed without another snapshot request. No browser page errors.

Native desktop/mobile sessions and a physical WAN were not exercised. Their shared runtime is covered by the tests above; app-wide regression freedom is not claimed.

Model: GPT-6. Harness: Codex.

Summary by CodeRabbit

  • Refactor

    • Updated remote environment request handling across authorization, session, pull request, shell snapshot, and thread operations.
    • Preserved existing endpoints, payloads, headers, timeouts, and response behavior.
    • Streamlined thread message updates while maintaining unchanged messages and correctly appending new ones.
  • Tests

    • Expanded coverage for invalid authentication responses and thread message updates.
  • Performance

    • Added benchmarks for remote environment operations and thread event processing.
  • User Impact

    • No user-facing behavior changes are expected.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This performance refactor changes shared remote HTTP and authentication code, including a file under the authorization directory. Despite its narrow scope and added tests, authentication-directory changes require human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review Change StackReview Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 195d0dc1-22c4-4692-b0ee-c6557c6e6a54

      📥 Commits

      Reviewing files that changed from the base of the PR and between addfb1390eea5e850fb5e235525f9eb6c4ade100 and 4d0bd4e548a23b1bad3aac02fecc9cc396d2f7a1.

      📒 Files selected for processing (12)
      • packages/client-runtime/src/authorization/remote.ts
      • packages/client-runtime/src/environment/descriptor.ts
      • packages/client-runtime/src/remotePerformance.bench.ts
      • packages/client-runtime/src/rpc/http.ts
      • packages/client-runtime/src/state/environmentHttpAuth.test.ts
      • packages/client-runtime/src/state/environmentHttpAuth.ts
      • packages/client-runtime/src/state/pullRequestDiffHttp.ts
      • packages/client-runtime/src/state/session.ts
      • packages/client-runtime/src/state/shellSnapshotHttp.ts
      • packages/client-runtime/src/state/threadReducer.test.ts
      • packages/client-runtime/src/state/threadReducer.ts
      • packages/client-runtime/src/state/threadSnapshotHttp.ts

      Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      The client runtime now uses grouped environment HTTP API clients across remote authorization, metadata, session, orchestration, and pull request requests. The thread reducer uses a single-pass message upsert. Tests and benchmarks cover the updated request handling and reducer behavior.

      Changes

      Environment HTTP group migration

      Layer / File(s)Summary
      Group client factory
      packages/client-runtime/src/rpc/http.ts
      Adds makeEnvironmentHttpApiGroupClient for constructing clients for specific EnvironmentHttpApi groups.
      Authenticated request flow
      packages/client-runtime/src/state/environmentHttpAuth.ts, packages/client-runtime/src/authorization/remote.ts, packages/client-runtime/src/state/environmentHttpAuth.test.ts
      Makes authenticated requests generic over the selected group. Remote token, session, and WebSocket-ticket operations use the grouped auth client. Invalid JSON responses are tested for all authenticated loaders.
      Environment request callers
      packages/client-runtime/src/environment/descriptor.ts, packages/client-runtime/src/state/session.ts, packages/client-runtime/src/state/shellSnapshotHttp.ts, packages/client-runtime/src/state/threadSnapshotHttp.ts, packages/client-runtime/src/state/pullRequestDiffHttp.ts
      Selects metadata, auth, orchestration, or pullRequests groups and invokes API methods directly on the grouped client.

      Thread reducer and performance validation

      Layer / File(s)Summary
      Thread message upsert
      packages/client-runtime/src/state/threadReducer.ts, packages/client-runtime/src/state/threadReducer.test.ts
      Replaces the previous find-and-map upsert with one map pass and verifies targeted updates, appends, and reference identity of unchanged messages.
      Runtime benchmarks
      packages/client-runtime/src/remotePerformance.bench.ts
      Adds benchmarks for remote HTTP operations and text-delta application on threads with 100 and 1,000 messages.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Merge Risk: ⚪ Minimal · up to 4d0bd

      This change reduces remote request and message-update processing overhead while preserving existing request and message-update behavior. No current merge-blocking risk remains.

      Suggested reviewers: juliusmarminge, t3dotgg

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 12 files.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly and concisely describes the primary changes: reduced remote request and message synchronization overhead.
      Description check✅ PassedThe description provides detailed change rationale, benchmark results, verification steps, scope, and limitations. It omits the template headings and checklist, but the required information is otherwi…
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge merged this6e8931d

    5. juliusmarminge closed this

Sign in to join this conversation.