Repository navigation
Read Blob snapshots through a shared cache of blocks (0.8.2) - #7
Merged
Merged
Conversation
Every read of a Blob (snapshots in IndexedDB and OPFS, the layers deltas lie over, readOnlyFile) now goes through an LRU of 16 KiB blocks, 32 MiB per storage by default. Missing blocks are read one run at a time, with the aligned 256 KiB around them, or 1 MiB ahead for forward reads; blocks read along wait apart and leave first. New readCache option on the storages. Adds an FTS5 benchmark in a Worker (script/test-browser.ts --fts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011zxsJtUFr4iK5q3Gkdscnk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011zxsJtUFr4iK5q3Gkdscnk
…den the forward window - The deprecated blocks option counts blocks of 1 MiB (as in 0.8.1) unless blockSize is given, instead of the new 16 KiB default - blockSize, readAround and readAhead must be finite - A read counts as running forward within the span read around, not one 16 KiB block, as 0.8.1 did with its 1 MiB blocks - The cache identifies a snapshot by its size too - Fix the size and the read cost given in comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011zxsJtUFr4iK5q3Gkdscnk
- A block taken along that does not fit beside the blocks in use is not kept, instead of evicting one - blockSize is at least 512, so block keys never overflow into those of other snapshots - Validate the deprecated blocks option on its own - --fts refuses a --runs that is not a number of at least 1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011zxsJtUFr4iK5q3Gkdscnk
commit: |
There was a problem hiding this comment.
🟡 Changes recommended
Cache metadata and large-read memory can grow beyond the configured budget, and benchmark failure handling needs correction.
5 open findings
What changed in this PR
Adds a shared block cache to improve random reads from Blob-backed SQLite snapshots.
Changes:
- Introduces configurable block caching with read-around/read-ahead behavior.
- Adds extensive cache tests and an FTS benchmark.
- Updates release documentation and version to 0.8.2.
| File | Description |
|---|---|
src/snapshots.ts |
Implements shared Blob block caching. |
snapshots.test.js |
Tests cache correctness, eviction, and sharing. |
test/browser/fts-worker.js |
Builds and queries the FTS benchmark database. |
test/browser/fts-bench.js |
Coordinates benchmark workers. |
script/test-browser.ts |
Adds the --fts benchmark command. |
README.md |
Documents snapshot caching. |
CHANGELOG.md |
Records the 0.8.2 changes. |
BENCHMARKS.md |
Documents FTS benchmark results. |
package.json |
Bumps the package version. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Key cached blocks by their content string, so nothing about a snapshot outlives its blocks in the cache - Of a read larger than the cache, copy only the blocks that can stay - Document that readAround and readAhead read at most a quarter of cacheBytes - --fts takes a whole number of runs, and a Worker that fails rejects its call instead of hanging Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011zxsJtUFr4iK5q3Gkdscnk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes slow random reads from Blob-backed snapshots. A profile of a full-text search in alinea's dashboard spent 14.6 s of 16 s in
FileReaderSync.readAsArrayBufferandBlob.slice.Problem
In 0.8.1,
readOnlyFilekept 4 blocks of 1 MiB, and used them only for reads that ran forward or whose blocks were all cached. Any other read was its ownslice+readAsArrayBufferof exactly the bytes asked. FTS5 and b-tree lookups read pages in random order, so nearly every page SQLite missed became its own synchronous Blob read.Change
slice+readAsArrayBufferper contiguous run of them.SnapshotStorage. It is shared by every database the storage opens and by snapshots that lie over the same layer (below). Blocks are keyed bycreatedAt:size:key, because eachstore.getreturns a new Blob object.readCache: {blockSize, cacheBytes, readAround, readAhead}onindexedDBSnapshots,opfsSnapshotsandSnapshotStorage.readOnlyFiletakes the same options. Itsblocksoption is deprecated and still counts blocks of 1 MiB.Uint8Arraypath, the snapshot format and the stored data are unchanged.CHANGELOG.md.Benchmark
bun script/test-browser.ts --fts(new) builds a 208 MB database with an FTS5 table and saves it to IndexedDB. A new Worker then runs two rounds of the same queries and countsFileReaderSyncreads. The queries are typed-out prefix MATCH searches, a broada*joined to the entries table, and 2,000 indexed lookups. Headless Chromium, median of 3 runs:match k*(first time)Round 1 makes 42% fewer reads but takes about as long. In this environment a read costs about 1 ms and grows with its size, and round 1 times vary by ±20% between runs. Where each read costs more, as with IndexedDB Blobs in the dashboard's profile, fewer reads should count for more. These numbers were measured before the review fixes. Details and other settings are in
BENCHMARKS.md.Testing
bun test: 374 pass. Browser tests in Chromium: 12 pass, including delta snapshots read in another Worker.snapshots.jsrebuilt from source, because there was no Emscripten in the environment. CI does the full build.🤖 Generated with Claude Code
https://claude.ai/code/session_011zxsJtUFr4iK5q3Gkdscnk
Generated by Claude Code