perf(mobile): reduce shell cache encoding work #15096
main fromrefs/pull/15096/head·merged by juliusmarminge View on GitHubLarge 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.
| Measurement | Before | After |
|---|---|---|
| Active elapsed time outside host-timer waits | 456.9 ms | 345.1 ms |
| Longest active segment | 15.37 ms | 11.95 ms |
| Total encoding elapsed time | 523.3 ms | 532.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.
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
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
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_statustofalsein 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.tsapps/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.tsThe 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 envelopeMerge Risk: ⚪ Minimal · up to
0b5efThe encoding change is mergeable after normal checks; no actionable issue is established.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Description check ⚠️ Warning 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 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 name Status Explanation Docstring Coverage ✅ Passed No 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 ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Title check ✅ Passed The 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.Approvability#
Verdict: Approved at
0b5ef27Macroscope'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
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).f06011a. Prior analysis still applies.macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this1c33f3b
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
efecd3c· PR result:f06011a· Source CI: successScenario 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.