Repository navigation
fix(browser): store migrated pages on open; keep only live pages (#411, #440) - #474
Merged
Merged
Conversation
#440) BrowserDb.open() now flushes the pages an open writes, so a v7 IndexedDB store is upgraded to v8 once instead of in memory on every open (#411). Free pages no longer hold bytes in the buffer or keys in IndexedDB (#440). Open drops the whole free list (after a v7 upgrade, the old v7 region); each commit drops the ids it newly put on the free list, which PageAllocator::finish_free_list now returns, so the cost stays O(change). The deletes go in the same IndexedDB transaction as the commit's pages and meta page. importGraph() also deletes the replaced database's keys. exportGraph() pads free pages with zeros up to the meta's page_count. Spec: docs/superpowers/specs/2026-10-07-browser-page-reuse-design.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Oct 7, 2026
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.
Summary
BrowserDb.open()flushes the pages an open writes, so a v7 IndexedDB store is upgraded to v8 once instead of in memory on every open.BrowserBufferBackendand no keys in IndexedDB. Open drops the whole free list (after a v7 upgrade, the old v7 region). Each commit drops only the ids it newly put on the free list:PageAllocator::finish_free_listnow returns them, so the cost stays O(change). The deletes go in the same IndexedDB transaction as the commit's pages and meta page.importGraph()also deletes the replaced database's keys. Before, a reopen loaded them next to the imported pages.exportGraph()writes free pages as zeros, padded to the meta'spage_count. A native test checks that a file with all-zero free pages opens, verifies clean and keeps committing, both just migrated and after saves.Chosen over "migrate into a fresh object store": the same path covers ordinary churn, and no IDB schema bump is needed. Spec:
docs/superpowers/specs/2026-10-07-browser-page-reuse-design.md.Acceptance (#440)
page_count − freelist_count, and growth stays under one page per transact (transacts_keep_only_live_pages).open_stores_migrated_v7_pages_and_drops_the_v7_region).unflushed_commit_reopens_at_the_previous_one).zeroed_free_pages_are_never_read, plus export→import round trip after churn).Known pre-existing gap (not in this PR)
If an IndexedDB flush fails (quota, abort), the dirty set is already drained and is not restored, so a later flush can miss pages. This is worth its own issue.
Test plan
cargo test— 1338 passed, 9 ignoredwasm-pack test --headless --firefox --features browser --lib— 32 passed. I checked that the new tests fail with release disabled (4) and with the open-time flush removed (browser: BrowserDb.open() does not write migrated pages back to IndexedDB #411 test)-D warnings: native (--all-features), wasm32-unknown-unknown--features browser, wasm32-wasip1;cargo fmt --check🤖 Generated with Claude Code
https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn