Skip to content

perf(mobile): reuse encoded rows in shell cache saves - #16129

Merged
juliusmarminge merged 1 commit into
t3code/mobile-perf/lazy-thread-move-availabilityfrom
t3code/mobile-perf/reuse-shell-row-encoding
Oct 8, 2026
Merged

juliusmarminge merged 1 commit into
t3code/mobile-perf/lazy-thread-move-availabilityfrom
t3code/mobile-perf/reuse-shell-row-encoding

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Mobile periodically persists the entire shell snapshot while threads stream. With 1,210 shells and five changing threads, every save re-encoded the other 1,205 rows through the schema codec.

Give each persistence store an encoder with a weak map of successfully encoded row objects. The shell reducer replaces changed rows and preserves unchanged row references, so only cache misses need the canonical row codec. Cold rows still encode in batches of 32 with host yields. Envelope validation and JSON serialization remain unchanged.

Scope and approval

Julius requested this mobile performance audit and one PR per measured hotspot in the maintainer session. This focused fix removes repeated serialization of unchanged shell rows without changing the stored format or product behavior. It is maintainer-directed work; there is no separate public issue or discussion approval link.

Release simulator evidence

Same optimized native Release binary, Hermes -O, dev=false. Same 1,210-thread fixture restored before each run, Home visible with settled history expanded, 20 Hz foreground stream plus four 2 Hz background streams for 15 seconds. Both runs emitted 300 + 120 events. Only the two production files in this PR differ in the bundle source maps.

Inclusive JS samples Before After
Shell-cache encoder stacks 184 9
Encoder share of active samples 12.0% 0.6%
Schema parser stacks 266 53
Active JS / total samples 1,531 / 11,330 1,574 / 13,611
Capture duration 20.80 s 20.86 s

Measurement details · Before Hermes trace · After Hermes trace

The baseline is the saved trace from the exact parent release bundle at 82d061a. This one pair measures repeated saves after startup, not cold sync. Sampling and generated text vary. Total active JS samples are roughly unchanged, so this is evidence of removing the targeted encoding work, not an overall app-speed or battery claim. There is no visible UI change.

Correctness and tradeoff

  • The reducer's immutable upserts retain other row objects; full snapshots supply fresh objects and encode cold. The weak map is per store, with no TTL, eviction worker, or global cache.
  • Validated row encodings are stored only after a successful batch. Failed rows are retried and still rejected. A cancelled save can retain completed valid batches.
  • One encoded copy remains reachable per live row. The memory delta has not been measured; removed row keys can be collected. Future in-place mutation of shell rows would invalidate the identity assumption.
  • Envelope encoding/stringification still visits the full snapshot.

Fifteen focused tests passed, including byte-identical canonical cold/warm payloads, replacement/addition/archive cases, invalid rows and cold-path cancellation. Targeted lint and formatting passed. The existing concurrency test uses fresh encoders; shared-instance concurrency is supported by immutable row values but has not received a separate test. Both iOS and Android use this mobile store; web/desktop, wire contracts, and providers are unchanged. Unrelated local widget edits are excluded.

Implementation: Claude Opus 5.5 through T3 Code. Integration, review, and release profiling: GPT-6 Astra through the Codex harness.


Devin Review

@juliusmarminge
juliusmarminge added this pull request to stack #15249 October 5, 2026 16:49
@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Oct 5, 2026
@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 5, 2026
@github-actions github-actions Bot added the size:M 30-99 changed lines (additions + deletions). label Oct 5, 2026
@juliusmarminge
juliusmarminge marked this pull request as ready for review October 5, 2026 16:49
@juliusmarminge
juliusmarminge force-pushed the t3code/mobile-perf/reuse-shell-row-encoding branch from f3e1405 to 272ed9c Compare October 5, 2026 16:52
@macroscopeapp

macroscopeapp Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 272ed9c

Macroscope's review found this PR approvable — This is a contained mobile cache serialization optimization that reuses successful row encodings while preserving canonical cold-path encoding, envelope validation, and stored output. Focused tests cover warm saves, row replacement and archiving, failures, and byte-identical payloads.

Notes:

  • Diff unchanged. Approvability was decided on eligibility alone.

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

You can add or adjust custom eligibility rules. Learn more.

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 5.0 KiB — 6.8 KiB ✅
Codex Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Codex Live turn WebSocket decoded — 20.9 KiB — 29.3 KiB ✅
Codex Live turn messages — 2 — 8 ✅
Claude Total thread wire — 5.0 KiB — 6.8 KiB ✅
Claude Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Claude Live turn WebSocket decoded — 21.2 KiB — 29.3 KiB ✅
Claude Live turn messages — 2 — 8 ✅

Baseline: unavailable · PR result: b25dec4 · 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.

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

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: 02c086b8-3cc7-42aa-b45f-afef514cf338
📥 Commits

Reviewing files that changed from the base of the PR and between d5ddcbb and 272ed9c.

📒 Files selected for processing (3)
  • apps/mobile/src/connection/environment-cache-store.test.ts
  • apps/mobile/src/connection/environment-cache-store.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

Shell snapshot encoding now uses a reusable encoder instance. The encoder caches successfully encoded rows by object identity and encodes uncached rows in chunks. The environment cache store creates the encoder and uses it when saving snapshots.

Changes

Shell snapshot encoding

Layer / File(s) Summary
Cache-aware row encoding
apps/mobile/src/connection/shell-cache-encoding.ts
makeStoredShellSnapshotEncoder returns an encoder that caches successful row encodings by object identity. It processes uncached rows in chunks and encodes the envelope after row processing.
Store integration and encoder tests
apps/mobile/src/connection/environment-cache-store.ts, apps/mobile/src/connection/environment-cache-store.test.ts
The store creates and uses an encoder instance. Tests cover cold and warm encoding, changed and archived rows, timer yields, and retry after a failed encoding.

Priority: ➖ Normal

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

Change: Refactor

Merge Risk: ⚪ Minimal · up to 272ed

The cache change has no established behavior or data-safety issue blocking merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, change, scope, verification, and tradeoffs. However, the required scope approval link is missing. It says the work was requested in a maintainer session but provi… Add a link to the triaged issue or maintainer discussion that contains explicit approval of the direction and scope. If the approval occurred in a private session, provide an acceptable reference or document the approval in a way that satis…
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring 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 3 files.
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 and concisely describes the main change: reusing encoded rows during mobile shell-cache saves.
Full details: Description check

Explanation

The description explains the problem, change, scope, verification, and tradeoffs. However, the required scope approval link is missing. It says the work was requested in a maintainer session but provides no link to that discussion or explicit approval, and it does not qualify for the template’s obvious-bug exception.

Resolution

Add a link to the triaged issue or maintainer discussion that contains explicit approval of the direction and scope. If the approval occurred in a private session, provide an acceptable reference or document the approval in a way that satisfies the repository’s scope-and-approval requirement.

✨ 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.

@juliusmarminge
juliusmarminge force-pushed the t3code/mobile-perf/reuse-shell-row-encoding branch from 272ed9c to bab9fdb Compare October 5, 2026 17:03
@juliusmarminge
juliusmarminge force-pushed the t3code/mobile-perf/reuse-shell-row-encoding branch from bab9fdb to f2f7378 Compare October 7, 2026 02:34
@juliusmarminge
juliusmarminge force-pushed the t3code/mobile-perf/reuse-shell-row-encoding branch 2 times, most recently from 5f0a42c to 58d8ae0 Compare October 8, 2026 05:31
@juliusmarminge
juliusmarminge force-pushed the t3code/mobile-perf/reuse-shell-row-encoding branch from 58d8ae0 to 1c40030 Compare October 8, 2026 05:39
@juliusmarminge
juliusmarminge force-pushed the t3code/mobile-perf/reuse-shell-row-encoding branch from 1c40030 to b25dec4 Compare October 8, 2026 05:41
@juliusmarminge
juliusmarminge merged commit 8a1fc41 into main Oct 8, 2026
34 of 37 checks passed
@juliusmarminge
juliusmarminge deleted the t3code/mobile-perf/reuse-shell-row-encoding branch October 8, 2026 05:49
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Oct 8, 2026
## What's Changed
* chore(review): remove the custom Approvability check by @esthor in pingdotgg/t3code#17018
* perf(mobile): show the cached thread list sooner and stop the freeze after it by @juliusmarminge in pingdotgg/t3code#16713
* fix(server): replaying a command no longer freezes the server by @SunkenInTime in pingdotgg/t3code#17041
* fix(server): opening a long thread no longer blocks the server for a second by @SunkenInTime in pingdotgg/t3code#17029
* fix(server,web,mobile): thread links reference the thread id, not a baked title by @juliusmarminge in pingdotgg/t3code#17017
* fix(web): messages with quotes or links no longer collapse when short by @flamboh in pingdotgg/t3code#16624
* refactor(web): PR loading skeleton shares the detail panel's layout by @flamboh in pingdotgg/t3code#15583
* fix(web): PR file headers keep the file name in narrow panels by @flamboh in pingdotgg/t3code#15562
* fix(web): PR timeline no longer shifts when its scrollbar appears by @flamboh in pingdotgg/t3code#15588
* fix(server): held queued wakes no longer keep delegated tasks running by @juliusmarminge in pingdotgg/t3code#17028
* fix(server): a message sent during a rollback no longer undoes it by @t3dotgg in pingdotgg/t3code#17079
* fix(web): PR file stats ignore the hide-whitespace toggle by @flamboh in pingdotgg/t3code#16162
* perf(mobile): omit duplicated turn items from bounded thread snapshots by @juliusmarminge in pingdotgg/t3code#15385
* perf(mobile): pause elapsed-time timers on hidden thread screens by @juliusmarminge in pingdotgg/t3code#15397
* fix(mobile): pause hidden home thread list updates by @juliusmarminge in pingdotgg/t3code#15705
* fix(mobile): restore file viewer insets and glass header by @juliusmarminge in pingdotgg/t3code#17073
* fix(web): PR code toolbar no longer overlaps in narrow panels by @flamboh in pingdotgg/t3code#15561
* fix(web): PR commit menu no longer stretches across the window by @flamboh in pingdotgg/t3code#15560
* fix(web): command palette scrollbar no longer clipped at the top by @flamboh in pingdotgg/t3code#17035
* fix(web): Usage breadcrumb stays centered on small viewports by @flamboh in pingdotgg/t3code#15552
* fix(mobile): stop refreshing Git status on streamed thread updates by @juliusmarminge in pingdotgg/t3code#15893
* fix(mobile): skip move indexes for empty and single-thread sections by @juliusmarminge in pingdotgg/t3code#16115
* perf(mobile): reuse encoded rows in shell cache saves by @juliusmarminge in pingdotgg/t3code#16129
* perf(mobile): skip showcase subscriptions in normal builds by @juliusmarminge in pingdotgg/t3code#16131
* perf(mobile): remove unused Home project sorting by @juliusmarminge in pingdotgg/t3code#16177
* perf(mobile): reduce move-menu index allocations by @juliusmarminge in pingdotgg/t3code#16256
* perf(mobile): skip impossible thread-key lookups by @juliusmarminge in pingdotgg/t3code#16263
* fix(mobile): collect UI runtime garbage on iOS memory warnings by @juliusmarminge in pingdotgg/t3code#16296
* fix(mobile): stop Git sheet refresh loop by @juliusmarminge in pingdotgg/t3code#16305
* fix(mobile): refresh Git status after reconnect by @juliusmarminge in pingdotgg/t3code#16329
* fix(mobile): update the iOS Git header menu when status changes by @juliusmarminge in pingdotgg/t3code#16330
* perf(mobile): reuse the settled sort when settled rows are unchanged by @juliusmarminge in pingdotgg/t3code#16369
* perf(mobile): highlight source files in small batches that keep grammar state by @juliusmarminge in pingdotgg/t3code#16729
* feat(web): quote chips show what you said about the quote by @flamboh in pingdotgg/t3code#15703
* feat(web): projectless threads show their machine in the sidebar by @flamboh in pingdotgg/t3code#17022
* fix(lineage): keep agent effort and speed after completion by @Bil0000 in pingdotgg/t3code#16925
* fix(mobile): align diff scrolling with glass headers by @juliusmarminge in pingdotgg/t3code#17085
* fix(web): workspace page headers can no longer grow past the top-bar height by @maria-rcks in pingdotgg/t3code#17086
* feat(mobile): redesign the Add environment sheet by @juliusmarminge in pingdotgg/t3code#17092


**Full Changelog**: pingdotgg/t3code@v0.0.46-nightly.20261008.2801...v0.0.46-nightly.20261008.2813

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.46-nightly.20261008.2813
github-actions Bot added a commit to davidvanderklay/t3code-flake that referenced this pull request Oct 8, 2026
## What's Changed
* chore(review): remove the custom Approvability check by @esthor in pingdotgg/t3code#17018
* perf(mobile): show the cached thread list sooner and stop the freeze after it by @juliusmarminge in pingdotgg/t3code#16713
* fix(server): replaying a command no longer freezes the server by @SunkenInTime in pingdotgg/t3code#17041
* fix(server): opening a long thread no longer blocks the server for a second by @SunkenInTime in pingdotgg/t3code#17029
* fix(server,web,mobile): thread links reference the thread id, not a baked title by @juliusmarminge in pingdotgg/t3code#17017
* fix(web): messages with quotes or links no longer collapse when short by @flamboh in pingdotgg/t3code#16624
* refactor(web): PR loading skeleton shares the detail panel's layout by @flamboh in pingdotgg/t3code#15583
* fix(web): PR file headers keep the file name in narrow panels by @flamboh in pingdotgg/t3code#15562
* fix(web): PR timeline no longer shifts when its scrollbar appears by @flamboh in pingdotgg/t3code#15588
* fix(server): held queued wakes no longer keep delegated tasks running by @juliusmarminge in pingdotgg/t3code#17028
* fix(server): a message sent during a rollback no longer undoes it by @t3dotgg in pingdotgg/t3code#17079
* fix(web): PR file stats ignore the hide-whitespace toggle by @flamboh in pingdotgg/t3code#16162
* perf(mobile): omit duplicated turn items from bounded thread snapshots by @juliusmarminge in pingdotgg/t3code#15385
* perf(mobile): pause elapsed-time timers on hidden thread screens by @juliusmarminge in pingdotgg/t3code#15397
* fix(mobile): pause hidden home thread list updates by @juliusmarminge in pingdotgg/t3code#15705
* fix(mobile): restore file viewer insets and glass header by @juliusmarminge in pingdotgg/t3code#17073
* fix(web): PR code toolbar no longer overlaps in narrow panels by @flamboh in pingdotgg/t3code#15561
* fix(web): PR commit menu no longer stretches across the window by @flamboh in pingdotgg/t3code#15560
* fix(web): command palette scrollbar no longer clipped at the top by @flamboh in pingdotgg/t3code#17035
* fix(web): Usage breadcrumb stays centered on small viewports by @flamboh in pingdotgg/t3code#15552
* fix(mobile): stop refreshing Git status on streamed thread updates by @juliusmarminge in pingdotgg/t3code#15893
* fix(mobile): skip move indexes for empty and single-thread sections by @juliusmarminge in pingdotgg/t3code#16115
* perf(mobile): reuse encoded rows in shell cache saves by @juliusmarminge in pingdotgg/t3code#16129
* perf(mobile): skip showcase subscriptions in normal builds by @juliusmarminge in pingdotgg/t3code#16131
* perf(mobile): remove unused Home project sorting by @juliusmarminge in pingdotgg/t3code#16177
* perf(mobile): reduce move-menu index allocations by @juliusmarminge in pingdotgg/t3code#16256
* perf(mobile): skip impossible thread-key lookups by @juliusmarminge in pingdotgg/t3code#16263
* fix(mobile): collect UI runtime garbage on iOS memory warnings by @juliusmarminge in pingdotgg/t3code#16296
* fix(mobile): stop Git sheet refresh loop by @juliusmarminge in pingdotgg/t3code#16305
* fix(mobile): refresh Git status after reconnect by @juliusmarminge in pingdotgg/t3code#16329
* fix(mobile): update the iOS Git header menu when status changes by @juliusmarminge in pingdotgg/t3code#16330
* perf(mobile): reuse the settled sort when settled rows are unchanged by @juliusmarminge in pingdotgg/t3code#16369
* perf(mobile): highlight source files in small batches that keep grammar state by @juliusmarminge in pingdotgg/t3code#16729
* feat(web): quote chips show what you said about the quote by @flamboh in pingdotgg/t3code#15703
* feat(web): projectless threads show their machine in the sidebar by @flamboh in pingdotgg/t3code#17022
* fix(lineage): keep agent effort and speed after completion by @Bil0000 in pingdotgg/t3code#16925
* fix(mobile): align diff scrolling with glass headers by @juliusmarminge in pingdotgg/t3code#17085
* fix(web): workspace page headers can no longer grow past the top-bar height by @maria-rcks in pingdotgg/t3code#17086
* feat(mobile): redesign the Add environment sheet by @juliusmarminge in pingdotgg/t3code#17092


**Full Changelog**: pingdotgg/t3code@v0.0.46-nightly.20261008.2801...v0.0.46-nightly.20261008.2813

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.46-nightly.20261008.2813
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant