Skip to content

perf(web): cache recent thread snapshots between switches - #272

Merged
nixuuu merged 1 commit into
perf/thread-cache-1from
perf/thread-cache-2
Nov 6, 2026
Merged

nixuuu merged 1 commit into
perf/thread-cache-1from
perf/thread-cache-2

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Switching back to a recent thread now paints its cached conversation immediately, then opens the BFF stream with that snapshot's journal checkpoint. The cache holds raw protobuf state and applies the shared reducer; unchanged timeline entries keep their identities during live handoff. Reconnect computes a fresh cursor URL, and a mismatched base retries with full state.

The SPA keeps an LRU of 12 threads / 64 MiB encoded protobuf bytes, in memory only. The current screen owns its state separately. No IndexedDB or localStorage is used. The cache clears on document departure and app-shell destruction, including desktop connection selection. Actions continue to reach the authoritative gateway and its current-state checks.

Two synthetic 500-turn / 3,001-item threads, actual development browser and BFF, real gateway and isolated Postgres:

Switch Before After
First content, three samples 300.2 / 287.2 / 311.1 ms 126.3 / 105.1 / 110.3 ms
Median 300.2 ms 110.3 ms
Initial SSE JSON data 6,952,035–6,952,159 B 791–801 B

Warm content appears before the network reply. A cold control still took 346 ms / 6,952,212 B. Numbers exclude transport/framing and are synthetic development measurements, not production guarantees. Long local browser rendering did not justify a separate tail-loading stage here.

Verification: install, gen:check, typecheck (0 Svelte errors/warnings), lint and formatting passed. Top-of-stack check:tmp (1,490 passed / 159 skipped / zero failures), web build and Expo lint passed. Visually checked the real browser at 1280×800 and 390×844 in light and dark, including actual title/model/worker, long text and horizontal overflow. With SSE delivery delayed by 2.5 seconds, cached content and the quiet local Syncing state stayed visible; scrollTop remained 54,355 and the first article kept the same DOM node after live handoff. No UI test suite was added. Protocol integration coverage is in the first layer.

Copy audit (§8): initial “Connecting…” text → existing timeline skeleton; a warm conversation uses the existing quiet “Syncing…” state. Known thread metadata remains visible. No new glossary term, decorative sentence or colour-only state. Draft stack; do not merge individual layers.

@nixuuu
nixuuu added this pull request to stack #274 November 6, 2026 11:25
@nixuuu
nixuuu marked this pull request as ready for review November 6, 2026 11:52
@nixuuu
nixuuu merged commit 7ecca47 into dev Nov 6, 2026
11 checks passed
@nixuuu
nixuuu deleted the perf/thread-cache-2 branch November 6, 2026 11:52
nixuuu added a commit that referenced this pull request Nov 6, 2026
Opening a long bot conversation currently transfers every message again.
This adds durable, owner-scoped checkpoints for bot conversations and
bot-to-bot exchanges, so clients can request only changed messages and
current control state.

The bot tables have their own commit-ordered key journal, following the
thread mirror epoch/cursor design. A checkpoint binds the owner, view
and revision. Message edits, deletion and turn failures produce
upserts/removals. A metadata digest confirms approvals, read state,
pending cards, configuration, streaming text, routines and reminders;
changed control state is replaced atomically. Missing/expired cursors,
gaps, another epoch, rewritten exchange membership and moves fall back
to a full projection.

Linked bot reads pass the cursor to the home through the existing route.
Offline reads retain the existing mirror path and gateway action
enforcement. Proto additions are opt-in: old clients get full snapshots,
and a home ignoring the new fields returns full state that new clients
can apply. No link protocol version change. Migration 0091 is the next
free number on the rebased dev; schema expectations and generated
contracts are included.

### Measurements

Single-run development-server measurements with a real local
gateway/Postgres and 3,000 stored messages, each containing about 2 KB
of long output. Browser first content is measured from route switch to
message DOM appearing. SSE bytes include the ready frame and initial
state, excluding HTTP/TLS headers and unrelated sidebar polling. The
after column uses the whole stack, including the opt-in web client in
the next layer.

| Measurement | Before | After |
|---|---:|---:|
| Web warm switch, first content | 3,819.9 ms | 187.2 ms |
| Initial bot SSE, unchanged reopen | 7,050,627 B | 393 B |
| Web cold route, first content | 4,512.9 ms | 910.2 ms |
| Initially mounted message rows | 3,000 | 100 |
| Android first content / bytes | Unverified | Unverified |

The baseline full protobuf was 6,772,217 B. Cold full history remains
approximately 6.77 MB: this does not add server-side pagination. The
cold browser sample includes development module loading; these are
observations, not statistical latency bounds. Android timing and runtime
visuals are unverified: the device tool's dev-client deep link failed
with `COMMAND_FAILED: adb exited with code 1`, including its advised
debug retry. No SSH/ADB UI fallback was used.

### Verification

- Real-gateway integration and schema tests: 28 passed, including
edits/deletes/failures, control confirmation, gap/epoch/view fallback,
owner isolation, cursor after restart, linked chat/exchange, and a home
ignoring the additive request fields.
- `bun install`, `bun run gen:check`, `bun run typecheck`, `bun run
lint`, `bun run format:check` passed on this stage after rebasing.
- Polish protocol/read-path documentation updated. No new UI copy in
this layer.

The bot mirror publisher still uses its existing full projection
protocol; this stack changes UI reads, not partner journal publishing.
Live control metadata is a complete replacement when changed, rather
than a second journal for approvals and linked thread cards.

Related: #271, #272, #273.
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