SQLite Write-Ahead Logging (WAL), MVCC Snapshot Isolation & FTS5 BM25 Indexing
Cloud workspaces spend 80–300 ms on REST round-trips just to open a project table or search notes. Pairing memory-mapped SQLite WAL B-trees with FTS5 Okapi BM25 inverted lists on Apple Silicon NVMe resolves multi-hundred-thousand-row queries locally in under 100 microseconds with zero row caps.
1. Sequential WAL Frames, Cumulative Checksums & Reader Marks
Under PRAGMA journal_mode = WAL and PRAGMA synchronous = NORMAL, committing transaction T_k appends dirty 4,096-byte B-tree pages to db.sqlite-wal prefixed by a 24-byte frame header containing page number, post-commit database size, (salt_1, salt_2), and a cumulative big/native-endian dual-word checksum (s_0, s_1). Active readers record their snapshot ceiling aReadMark[i] = mxFrame inside shared -shm memory so PASSIVE checkpoints never overwrite pages visible to an in-flight UI query.
2. Memory-Mapped B-Tree Fanout & Zero Syscall Overhead
Enabling bounded PRAGMA mmap_size = 268435456 maps clean database extents directly into process virtual address space backed by the macOS Unified Buffer Cache—eliminating pread() kernel transitions and user-space page-cache double buffering during root-to-leaf binary search (depth 3–4 for 10^7 rows).
3. Varint Postings Lists & Robertson-Zaragoza Okapi BM25
FTS5 delta-encodes sorted (rowid, col, token_offset) postings in 7-bit varints inside shadow _data B-tree blobs and scores multi-term queries Q = {q_1, ..., q_m} against document D via length-normalized BM25:
IDF(q_i) = ln(1 + (N_docs - n(q_i) + 0.5) / (n(q_i) + 0.5))
BM25(D, Q) = sum_(i=1..m) IDF(q_i) * (f(q_i, D) * (k_1 + 1))
/ (f(q_i, D) + k_1 * (1 - b + b * (|D| / avgdl)))
// Default FTS5 parameters: k_1 = 1.2 (saturation), b = 0.75 (document-length normalization)4. Interactive Multi-Seat Cloud SaaS TCO Calculator
Compare per-seat cloud workspace and database costs against Destiny’s local-first + browser studio plans.
Cite reproducible Apple M4 Pro Unified Memory benchmark receipts in engineering repositories.
SQLite WAL, MVCC & FTS5 BM25 — FAQ
Direct answers on non-blocking WAL snapshots, -shm O(1) hash indices, BM25 term saturation, and open archival file ownership.
- How does SQLite WAL mode allow concurrent UI reads while background AI or crawlers write?
- Rollback-journal mode locks the entire database file during writes. Write-Ahead Logging (PRAGMA journal_mode = WAL) appends modified 4 KiB pages sequentially to the -wal file with a monotonic salt/checksum header, allowing readers to pin an end-mark frame mxFrame and enjoy non-blocking MVCC snapshot isolation while a writer appends newer frames.
- Why does the -shm WAL-index hash table keep page lookups O(1) without scanning the entire WAL?
- The memory-mapped -shm file partitions WAL frame numbers into 4,096-entry open-addressed multiplicative hash slots keyed by database page number P. Readers locate the latest committed frame <= mxFrame in constant L1/L2 cache probes before falling back to the main .db B-tree page.
- How does FTS5 Okapi BM25 improve local document search over SQL LIKE or raw TF-IDF?
- Linear TF saturates poorly when a single long log file repeats a token 500 times. Okapi BM25 bounds term frequency asymptotically via tf * (k_1 + 1) / (tf + k_1 * (1 - b + b * (|D| / avgdl))) with k_1 = 1.2 and length normalization b = 0.75, weighted by Robertson-Sparck Jones inverse document frequency.
- Are local SQLite workspace databases in Destiny portable without vendor lock-in?
- Yes. Standard IEEE/Library-of-Congress archival SQLite 3 database files and Markdown folders reside directly on your Mac APFS volume—readable by sqlite3 CLI, Python, DuckDB, or any open tool.