Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(mobile): reduce shell cache encoding work #15096

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/15096/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Large mobile shell-cache saves encode every thread through an Effect schema middleware. This adds work to the JavaScript thread while the user navigates. Encode canonical thread schemas in 32-row chunks instead, preserving host-timer yields, validation, date transforms, cancellation, and the persisted format.

Before/after measurements ran both the exact base encoder and this encoder in the same Hermes runtime, alternating order, with 1,004 synthetic thread shells and a 1.54 MB cache payload. Medians exclude the first two of nine iterations.

MeasurementBeforeAfter
Active elapsed time outside host-timer waits456.9 ms345.1 ms
Longest active segment15.37 ms11.95 ms
Total encoding elapsed time523.3 ms532.2 ms

Active elapsed time fell 24.5%. This is instrumented elapsed time, not a CPU sampling profile. Total save latency did not improve: React Native timer scheduling still dominates completion. This PR does not claim faster thread loading or navigation.

Instrumented raw samples · Uninstrumented raw samples

Benchmark scripts and samples. A repeat with all other development connections disabled measured 449.8 → 335.5 ms active elapsed time, consistent with the first run.

Validation: all 12 environment-cache-store tests pass, mobile TypeScript check passes, and targeted lint passes. Tests cover byte-identical canonical encoding, optional/date fields, archived rows, invalid input, yielding, interruption, and concurrent saves. The final JSON stringify remains synchronous. The change is mobile-only; shared wire contracts, web, desktop, and provider behavior are unchanged.

The matching native development client now builds and runs successfully after disk cleanup. Repeating the encoder benchmark there measured 513.04 → 399.00 ms active elapsed time, 18.18 → 13.87 ms longest active segment, and 530.42 → 533.07 ms total elapsed time. Matching-native raw samples. This confirms reduced encoding work with no save-latency improvement. The matching 1.4 client has also been built and exercised against a clean equivalent fixture.

Current-JavaScript smoke test opening the 5,000-message fixture, using the installed development shell. This recording is not a before/after latency comparison.

Current JavaScript opening the synthetic 5000-message thread

Broader audit: version-comparison measurements and limitations. The clean 1.4 run has the same 1,003 synthetic threads and 8,100 messages. Its shell HTTP response was about 30 ms versus 75 ms for current, and Hermes shell decoding was about 164 ms versus 225 ms. The native development captures did not establish a general navigation regression; they are not release-device tap-to-content timings. Current navigation captures already include the cache-encoding layer. A further chunked-cache-decoding experiment was rejected: despite shorter isolated pauses, it delayed first thread rendering during actual cold starts. Its measurements and rejected patch are included in the audit bundle; it is not in this stack.

Implementation: Claude Opus 5.5 through T3 Code's Claude agent. Review and measurements: GPT-6 Astra through the Codex harness in T3 Code.

    1. juliusmarminge changed the title

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. juliusmarminge added labelsmacroscope-review

    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: efecd3c · PR result: f06011a · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      ⚙️ Run configuration
      • Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 86fcb27a-936e-4e5d-892e-1dcf3baf823b
      📥 Commits

      Reviewing files that changed from the base of the PR and between 0b5ef2777408af174195bc867f1a257d4aaab36f and f06011a4fee59634b6be99f11cfc41e1edf69d7f.

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 650df372-2978-4c40-a8f9-e9adc7728315
      📥 Commits

      Reviewing files that changed from the base of the PR and between fed41fa88bb27cb4325cb208d571393850bc63c2 and 0b5ef2777408af174195bc867f1a257d4aaab36f.

      📒 Files selected for processing (2)
      • apps/mobile/src/connection/environment-cache-store.test.ts
      • apps/mobile/src/connection/shell-cache-encoding.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.


      📝 Walkthrough

      Walkthrough

      The snapshot encoder now encodes active and archived rows in 32-row chunks, yields between chunks, and encodes the snapshot envelope. Tests compare output with the original schema encoder and cover optional fields, dates, invalid data, timer yields, and concurrent encodings.

      Changes

      Shell-cache encoding

      Layer / File(s)Summary
      Chunked snapshot encoding
      apps/mobile/src/connection/shell-cache-encoding.ts, apps/mobile/src/connection/environment-cache-store.test.ts
      The encoder processes active and archived rows in chunks, yielding between chunks before encoding the envelope. Tests check output equivalence, optional fields, dates, timer yields, invalid rows and envelopes, and concurrent encodings.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Refactor

      Sequence Diagram(s)

      sequenceDiagram
        participant Encoder as encodeStoredShellSnapshot
        participant RowCodec as Thread row codec
        participant HostTimer as Host timer
        participant EnvelopeCodec as Stored snapshot codec
        Encoder->>RowCodec: Encode active and archived rows in chunks
        Encoder->>HostTimer: Yield between chunks
        Encoder->>EnvelopeCodec: Encode and validate snapshot envelope

      Merge Risk: ⚪ Minimal · up to 0b5ef

      The encoding change is mergeable after normal checks; no actionable issue is established.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Description check⚠️ WarningThe description explains the problem, implementation, scope, measurements, and verification in detail. It does not provide the required scope-and-approval information: a triaged issue or maintainer ap…Add a Scope and approval section. Link the triaged issue or discussion with explicit maintainer approval of the direction and scope, or explain why this focused change qualifies for the stated exemption without prior approval.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
      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 identifies the mobile shell-cache encoding performance change and is concise.
      Full details: Description check

      Explanation

      The description explains the problem, implementation, scope, measurements, and verification in detail. It does not provide the required scope-and-approval information: a triaged issue or maintainer approval, or an explanation of why the change qualifies for an exemption.

      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.
    6. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 0b5ef27

      Macroscope's review found this PR approvable — This mobile-only optimization bounds shell-cache row encoding into host-yielding chunks while preserving canonical validation and byte-identical persisted output. The production change is localized, and the expanded tests cover serialization, invalid data, concurrency, interruption, and scheduling behavior.

      No code changes detected at f06011a. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    7. juliusmarminge merged this1c33f3b

    8. juliusmarminge closed this

Sign in to join this conversation.