Skip to content

perf(threads): warm mobile caches and offline linked mirrors - #629

Merged
nixuuu merged 1 commit into
perf/thread-cache-webfrom
perf/thread-cache-mobile
Nov 13, 2026
Merged

nixuuu merged 1 commit into
perf/thread-cache-webfrom
perf/thread-cache-mobile

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Mobile now warms its existing persistent thread cache while the application is foreground and its overview connection is live. Restarted clients load the durable per-thread checkpoint and fetch only sequence deltas. Linked thread warming reads the local committed mirror, including while its source computer is offline.

  • At most 16 selected threads, including 10 recent sidebar roots, with one job and at least five seconds between starts (12 reads/minute maximum). Working/unseen/pinned threads join the bounded set; the archive is excluded.
  • Navigation, inactive/background state and connection loss cancel warming. Optional ExpoBattery support pauses in Low Power Mode when the existing native binary exposes it; no new native dependency or build is required.
  • The memory cache retains at most 16 entries / 24 MiB; existing disk limits and pairing/certificate fences remain. Mobile diagnostics starts timing at the tap and records current-state layout/rAF, cache hits, request counts and encoded bytes. Local thread identity guards keep retained stack screens from marking another thread's opening current.
  • Shared scheduling rotates waiting threads to avoid starvation. Search/project filters affect the recent set, with debounced search changes. Recent roots always follow Last activity (last reply, falling back to creation), independently of Created/Custom display order and pin positions; working/unseen/pinned threads join within the shared cap. The sidebar retains its merged manual-order controls. Desktop cache reads are fenced against late completion after clear/reset. Polish docs describe these behaviors.
  • Migration 0134 retains at most 256 immutable records / 256 KiB per mirrored thread and epoch, including tombstones. A rebuild also retains the previous visible epoch. Owner-scoped background reads return at most four 64-record / 64-KiB batches without contacting the source. Missing/old suffixes reset only the existing bounded, pageable window. Unlink removes the suffix through the existing FK cascade. Polish data-model and retention docs describe the storage limits. Migration 0133_thread_order and its expected schema entry are preserved alongside 0134.

Validation on the final stack: install, gen:check, full typecheck, lint, format:check and web build passed with nice. Focused check:tmp passed cache warming 6 tests / 41 assertions, linked mirrors 1/36, schema 23/85, sidebar ordering 5/22 and client diagnostics 9/70, with empty temp directories. Warming covers head owner scoping, bounded tails, delta reconnect, persistent mobile restart and recency independent of display/manual ordering. Current-head CI static checks, web/Linux build and commitlint passed; all four test shards are still running. A previous local full attempt was stopped after 1,092 passing tests and green CI on the preceding stack; it is not a completed local full pass for these heads.

Native before/after measurements could not run: device discovery failed twice with “Device list failed: Could not communicate with device support. Try refreshing devices.” No APK/EAS build was attempted. Therefore mobile frame time, battery use, requests/minute and native memory remain unverified; limits are implementation budgets, not measurements. The one-frame target is not established. Web measurements and their caveats are recorded on the preceding PR.

Stack 624 is based on dev cfb9846, including the merged sidebar-sorting stack and #628 citations. The generated protobuf and schema conflicts retain both behaviors. gh stack rebase completed; neither gh-stack-rebase-state nor Git's active rebase state remains. Current head: 7fa1423. All PRs remain draft. Measurement limitations above remain open.

Copy audit (§8): no additional product labels in this layer; it records the diagnostics labels introduced by the preceding layer. No merge requested; keep the entire stack draft until the remaining evidence is resolved.

@nixuuu
nixuuu added this pull request to stack #624 November 13, 2026 09:51
@nixuuu
nixuuu force-pushed the perf/thread-cache-mobile branch 3 times, most recently from 6a917e2 to 32cf309 Compare November 13, 2026 10:08
@nixuuu nixuuu changed the title perf(threads): warm durable mobile caches in the foreground perf(threads): warm mobile caches and offline linked mirrors Nov 13, 2026
@nixuuu
nixuuu force-pushed the perf/thread-cache-mobile branch 2 times, most recently from f639dcb to 580ba33 Compare November 13, 2026 10:33
@nixuuu
nixuuu force-pushed the perf/thread-cache-mobile branch from 580ba33 to 7fa1423 Compare November 13, 2026 10:44
@nixuuu
nixuuu marked this pull request as ready for review November 13, 2026 10:56
@nixuuu
nixuuu merged commit 3f57cbe into dev Nov 13, 2026
11 checks passed
@nixuuu
nixuuu deleted the perf/thread-cache-mobile branch November 13, 2026 10:57
nixuuu added a commit that referenced this pull request Nov 13, 2026
A retained thread panel continued `GetThreadPanel` polling every five
seconds while the app was backgrounded. Covered native-stack screens
also retained clocks and decorations. Scope recurring work to foreground
screen visibility, share countdown ticks, and cancel diagnostics uploads
on suspension. A pure-TS lifecycle regression guard covers suspension,
resumption, duplicate activity events and teardown.

Fixes: #559

Related: #629

| Instrumented path | Before | After |
| --- | ---: | ---: |
| Visible thread panel, recurring reads/min | 12 | 12 |
| Background/covered thread panel, recurring reads/min | 12 | 0 |
| 20 mounted request countdowns, foreground timers | 20 | 1 |
| Same countdowns, background timers | 20 | 0 |

Method: temporary hook instrumentation outside the repository, executing
the production query cache and hooks with a simulated 120-second clock.
These are timer/request counts, not native CPU, FPS, React render rates,
hardware wakeups or battery measurements. No conversation payloads were
captured.

Native profiling is blocked: T3 Device list and open report `Could not
communicate with device support. Try refreshing devices.` Refreshing
once did not recover the service. SSH profiling was available, but
Android was in `DevLauncherErrorActivity` with zero recorded app frames.
Its 0.2% process CPU is therefore excluded as an invalid Canopy
baseline. iOS's installed process was at 0.0% in `ps`, also without a
verified scenario. No native before/after claim is made.

| Requested native scenario, both platforms | CPU / JS+UI FPS /
renders/s / wakeups / requests per minute |
| --- | --- |
| Thread list with 2+ Working threads | Unavailable before and after |
| Streaming thread | Unavailable before and after |
| Idle open thread | Unavailable before and after |
| PR panel | Unavailable before and after |
| List idle for two minutes | Unavailable before and after |

Inspection found UI/native-thread animation loops, stable list keys,
memoized timeline/tree rows, and the existing shared status-label clock.
The warmer remains bounded to one request at a time and at most 12
starts/min; unchanged heads do not schedule reads. No hot-message log
spam or animated backdrop blur was found. The 24-slice text shimmer and
continuous composer geometry sampling still need a native GPU/layout
profile. This PR only suspends those paths when hidden/backgrounded; it
does not claim to eliminate foreground heating.

Validation uses `nice -n 10`: install, gen:check, typecheck, repository
lint, format:check and web build passed. The focused lifecycle
regression test passed. Both native JS/Hermes exports passed
(approximately 12 MB each). Full check:tmp passed on the combined
changes: 2,749 passed, 166 skipped, zero failures, and nothing left in
the checked temp directory. All CI checks passed at this head. Expo
ESLint has pre-existing findings: isolated `dev` baseline 82 errors,
changed tree 79, with no new file/rule errors. No UI suites, EAS builds,
release builds, publications or native dependency changes.

Native fingerprints are unchanged in the same local stable config:

- iOS: `74705db3a68907bc28379bb9b1080a227bc0755b`
- Android: `7d38be8f5c9bf842d62060c75820a206f99c87e3`

UI copy is unchanged. Native visual verification remains blocked by
device support.
nixuuu added a commit that referenced this pull request Nov 13, 2026
## Projekt workspace'u — zaakceptowany układ v2

Podgląd plików przechodzi z modala do zakładek jednego wątku. Sygnet
projektu, skracany tytuł i karty dzielą rząd nagłówka, z aktywną kartą
zawsze widoczną i przełącznikiem overflow. Prawy rail obsługuje jeden
minimalny moduł. Bez modułu podsumowanie jest dokowane i widoczne; z
modułem jest zamkniętą domyślnie kartą pływającą. Na wąskich ekranach
obie powierzchnie używają arkuszy.

Użytkownik zaakceptował układ v2 i udzielił jawnej zgody na
implementację. Przyjęte decyzje: jeden zastępowalny czysty preview,
utrwalany przez Edit/Keep tab/dwuklik, zakres cwd/worktree wątku i
mobilna edycja natywna bez kolorów podczas pisania (kolory w viewerze i
Preview changes). Usunięto sekcję otwartych decyzji.

Dokument uwzględnia jeden przycisk menu wiersza (#608), zachowanie
treści PR przy odświeżaniu (#611), bounded warming/cache transkryptu
(#622/#623/#629), niezależne sortowanie sidebara (#617/#619/#626),
kompaktowy tekst stanów preview (#634), poprawne stany ChoiceControl
(#637), kolejkę kontynuacji (#630) i podsumowania jej wierszy (#633).
Nie dodaje pełnych snapshotów ani prefetch plików podczas warming.

Siedem kompletnych warstw będzie osobnym stosem z podstawą dev.
Wszystkie PR implementacyjne pozostaną draftami do ukończenia i
weryfikacji całości oraz wspólnego scalenia przez maintenera. Migracje
muszą zachować monotoniczność względem aktualnego dev. Dokumentacyjny PR
po zielonym CI jest gotowy do scalenia przez maintenera.

## Weryfikacja i ograniczenia

- Rebase na dev `1626a3e6b05494e7aec77942bd818950468a3b58` bez
konfliktów.
- `nice -n 10 bun run format` i `nice -n 10 bun run format:check`
przeszły. Konfiguracja pomija Markdown; dokument sprawdzono ręcznie.
`git diff --check` bez błędów po usunięciu pustej linii końcowej.
- Brak zmian kodu aplikacji i kontraktów; testy wykonania oraz pomiary
budżetów należą do stosu implementacyjnego.
- Samodzielna makieta v2 poza repozytorium, 32 435 bajtów, przezroczyste
html/body, trzy stany × trzy szerokości × dwa motywy. Poprzednio
wyrenderowana i obejrzana bez błędów konsoli.

## Copy audit (§8)

Brak zmian produkcyjnych etykiet. Projekt zachowuje `Thread`, `Keep
tab`, `Thread details`, `Open in tab`, `Collapse panel` / `Show panel`
oraz dostępne nazwy obu kontekstów `+`. Zachowuje jeden przycisk menu
wiersza i kompaktowy tekst statusów pliku. Krótkie i długie etykiety są
pokazane w makiecie; rzeczywiste powierzchnie i stany będą audytowane w
każdej warstwie UI.
nixuuu added a commit that referenced this pull request Nov 14, 2026
When an off-screen mobile thread advances beyond the warmer's 256-record
replay limit, its fresh window currently overwrites the reader's loaded
history. Returning then loses older pages and the reading anchor.

Mobile now uses the shared `RetainedThreads` for recently opened views.
Fresh warm windows advance a separate cache copy, while the retained
view keeps its pages, history boundary and cursor. Reopening renders
that view and resumes its own cursor with incremental batches. Ordinary
background deltas still update retained views. Retention is bounded to
12 views / 12 MiB encoded, with mounted screens protected; existing
memory/disk cache limits remain separate. Pairing cleanup clears
retention before disk work.

Manual work-fold and tool-group choices now belong to the retained view
and survive reopening. Cell heights remain owned by native `FlatList`:
reusing them across screens would require a wider list-layout change and
device verification, so this follow-up leaves them unchanged.

The shared retention also guards an idle-leave race: accounting an old
retained view after a warm fallback cannot overwrite the warmer's newer
cache checkpoint.

Validation:
- `bun install`, `bun run gen:check`, full `bun run typecheck`, `bun run
lint` (repository oxlint), `bun run format:check`: passed locally with
`nice`.
- Focused `check:tmp` for `thread-warming.test.ts` and
`mobile-thread-cache.test.ts`: 16 passed, 128 assertions, no failures,
empty temp directory. Includes real-gateway web/mobile replay after 300
off-screen records, retained pages and cursor, batches only on reopen,
retention count/byte limits, shown-screen protection, pairing cleanup
and delayed-leave cache isolation. No UI suites added.
- iOS and Android Hermes exports: passed. iOS bytecode: 11,760,257
bytes; asset directory: 6,506,870 bytes. Android bytecode: 11,751,871
bytes; asset directory: 6,506,484 bytes. Production-profile EAS
fingerprints are unchanged before/after: iOS
`6ddec9ef559ee0095ac33e94ff9418a942053b17`, Android
`5f6eae3ab278f1cd543e9ed763f923a319b65ec9`.
- Additional Expo ESLint has existing React Hooks failures (91 errors /
19 warnings across mobile). Comparing the affected files against `dev`
found the same existing errors and two fewer warnings; no new errors.
The required repository oxlint check passes.
- Full suite is left to CI because host load rose above 8 during checks.
Device checks are blocked: no device host. Exports do not establish
native anchor/frame-time behavior.

Copy audit (docs/copy.md §8): no UI text changed. Polish
mobile/performance documentation updated.

`git show` confirms #623 introduced web/desktop warming; mobile's direct
cache-replacement adapter was added by #629. This corrects that
pre-existing mobile behavior, not #687.

Fixes: #629
Related: #687
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant