Skip to content

perf: cut the 15.8s cold-start stall (exploration 0233, Wave 1)#290

Merged
crs48 merged 5 commits into
mainfrom
claude/0233-the-15-second-cold-first-query-opfs-page-in-and
Jun 26, 2026
Merged

perf: cut the 15.8s cold-start stall (exploration 0233, Wave 1)#290
crs48 merged 5 commits into
mainfrom
claude/0233-the-15-second-cold-first-query-opfs-page-in-and

Conversation

@crs48

@crs48 crs48 commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Implements Wave 1 of exploration 0233 — the cheap, safe cold-read mitigations. The boot-debug trace (enabled by #288) finally named the culprit in one line:

[xNet] sqlite op query {"lane":"interactive","queueMs":0,"execMs":15858}

One landing query, 15.8 s of real execution, queueMs:0 — and every op after it execMs:0. That's a cold OPFS page-in of the first query's working set on the single SQLite worker; the 256 MB page cache only helps re-reads, so it never touched the first read. The file is large/fragmented (a 424k-row append-only change log + 1.3M-row scalar index grown interleaved), so the cold read faults pages scattered across it.

What's in this PR

  • B1 — PRAGMA mmap_size (web.ts): memory-map reads so the first cold query faults via the OS instead of thousands of synchronous 8 KiB reads. Guarded — a no-op where opfs-sahpool doesn't support it. This is the lever for the first read.
  • A3 — one-time idle VACUUM (db-vacuum.ts): defragments the OPFS file so subsequent cold boots fault a smaller, denser working set. Mirrors the 0229 presence cleanup (one-shot, localStorage-gated, idle-scheduled, off the critical path, never throws). Logs file size before/after — which also captures the db stats measurement the doc asked for.
  • C2 — defer the prewarm fan-out (WorkingSetPrewarm.tsx): mounts the five prewarm subscriptions one animation frame late so the active route's own query reaches the worker first and is the one that pays the cold read and paints.

Deliberately deferred (separate, focused PRs)

The doc is a multi-wave plan that gates later waves on measurement and touches the protocol kernel — implementing them blind here would be reckless:

  • Capture db stats / instrument the ~4.4 s secondary gap — runtime observations; A3 now logs the file size, and the rest needs a live capture against the user's OPFS data.
  • C1 instant-shell snapshot — a new persistence + write-through + render path; its own feature.
  • A1 change-log compaction + A2 split changes DBchanges is the signed, hash-chained protocol kernel (0200, golden vectors). Pruning it needs a spec + cross-impl test updates.
  • D1 WASM stream-compile (~1 s, secondary) and D2 hub redeploy (ops; clears the orthogonal INVALID_HASH).

The 0233 doc stays [_] (3/10 implementation items done) — Wave 1 lands here; the architectural waves follow with measurements in hand.

Test plan

  • New db-vacuum.test.ts (3 cases: opfs vacuum+latch, memory-skip-no-latch, flag no-op).
  • @xnetjs/sqlite + apps/web: typecheck clean, full suites green (677 tests in touched areas).
  • Pre-push full-suite "failures" were a core.bare flip from the hook's own pnpm install breaking devkit git tests — all pass with healthy git; none are in touched code.

🤖 Generated with Claude Code

xNet Test and others added 5 commits June 26, 2026 14:57
…B bloat)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…33 B1)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Also logs DB size before/after, which captures the db-stats measurement 0233
asked for. Mirrors the 0229 presence-blob cleanup: one-shot, localStorage-gated,
idle-scheduled, never on the boot critical path, never throws.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ry goes first (0233 C2)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@crs48 crs48 temporarily deployed to pr-290 June 26, 2026 22:08 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

🖼️ UI changes in this PR

No visual differences detected in the changed UI.

CI run

github-actions Bot added a commit that referenced this pull request Jun 26, 2026
github-actions Bot added a commit that referenced this pull request Jun 26, 2026
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Preview removed for PR #290.

@crs48 crs48 merged commit b102acd into main Jun 26, 2026
15 checks passed
@crs48 crs48 deleted the claude/0233-the-15-second-cold-first-query-opfs-page-in-and branch June 26, 2026 22:15
github-actions Bot added a commit that referenced this pull request Jun 26, 2026
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