8000 perf: skip redundant page cache allocation in BrowserDb by adityamukho · Pull Request #342 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

perf: skip redundant page cache allocation in BrowserDb - #342

Merged
adityamukho merged 1 commit into
mainfrom
275-browserdb-page-cache
Aug 23, 2026
Merged

adityamukho merged 1 commit into
mainfrom
275-browserdb-page-cache

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

  • BrowserDb::open_in_memory(), open(), and import_graph() now pass page cache capacity 0 to PersistentFactStorage::new instead of 256. BrowserBufferBackend already keeps every page resident in a HashMap (pre-loaded from IndexedDB at open time), so the LRU PageCache on top of it was a redundant RAM-to-RAM copy plus bookkeeping on every read.
  • Fixed a latent bug in PageCache uncovered while implementing this: PageCache::new(0) previously meant unbounded, not disabled — the eviction loop's capacity > 0 guard skipped eviction, but insertion still ran unconditionally, so every page ever read would have accumulated forever with no eviction. Naively wiring 0 through without this fix would have made memory usage strictly worse than the status quo. capacity == 0 now disables the cache outright: get_or_load reads straight through to the backend and put_dirty is a no-op. No existing caller passed 0 before this change, so no other behaviour is affected (verified: full native test suite passes unchanged).
  • Added PageCache::capacity() and a #[cfg(all(target_arch = "wasm32", feature = "browser", test))]-gated PersistentFactStorage::page_cache_capacity() accessor so the new BrowserDb tests can assert the constructors wire this up correctly. The accessor is test-only and compiled out of release WASM builds.
  • OpenOptions::page_cache_size (native src/db.rs) was intentionally left untouched — BrowserDb doesn't use OpenOptions at all, and that option is native-only territory owned by the companion issue perf: skip page cache allocation for in-memory databases #274.

Closes #275

Test plan

  • cargo test (native, full suite) — 0 failed, all passing, including 2 new PageCache zero-capacity unit tests
  • cargo clippy --all-features -- -D warnings — clean
  • cargo fmt --check — clean
  • cargo check --target wasm32-unknown-unknown --features browser --tests — compiles clean, confirming the 3 new #[wasm_bindgen_test] assertions (open_in_memory_disables_page_cache, open_disables_page_cache, import_graph_disables_page_cache) type-check against the real BrowserDb/PersistentFactStorage API
  • Note: this repo's CI has no job that builds/tests the wasm32 + browser target (only Rust workflow's native cargo build/cargo test across OSes, plus --all-features clippy on native), and no headless-Chrome/wasm-pack test runner was available in this environment, so the new wasm_bindgen_tests could not be executed end-to-end locally — only compiled. They exercise real code paths already covered indirectly by the existing in_memory_transact_and_query / idb_persistence_round_trip tests in the same file, so correctness risk is low.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YMWSutMLJJ7Y5b8hs9ZaCU

BrowserDb::open_in_memory(), open(), and import_graph() now pass page
cache capacity 0 to PersistentFactStorage::new instead of 256.
BrowserBufferBackend already holds every page resident in a HashMap
(pre-loaded from IndexedDB at open time), so the LRU PageCache on top
of it was a redundant RAM-to-RAM copy plus bookkeeping on every read.

This required fixing PageCache::new(0) itself: it previously meant
"unbounded" rather than "disabled" (the eviction loop's capacity > 0
guard skipped eviction, but insertion still ran unconditionally), which
would have made this change strictly worse — an ever-growing duplicate
of every page ever read, never reclaimed. Capacity 0 now disables the
cache outright: get_or_load reads through to the backend and put_dirty
is a no-op. No existing caller passed 0 before, so no other behaviour
changes.

Added PageCache::capacity() and a wasm+test-only
PersistentFactStorage::page_cache_capacity() accessor so the new
BrowserDb tests can assert the constructors wire this up correctly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YMWSutMLJJ7Y5b8hs9ZaCU
@codecov
codecov Bot commented Aug 23, 2026
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/storage/persistent_facts.rs 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

8000

@adityamukho
adityamukho merged commit 572461d into main Aug 23, 2026
17 checks passed
@adityamukho
adityamukho deleted the 275-browserdb-page-cache branch August 23, 2026 17:06
adityamukho added a commit that referenced this pull request Oct 7, 2026
…the IndexedDB flush (#470)

checkpoint(), importGraph() and every write collected dirty pages with
read_page_raw(id).ok() in a filter_map, so a page that failed to read
was silently left out of the flush to IndexedDB while the call reported
success. A shared take_dirty_pages helper (the same one v3 has since
#469) now returns the read error.

No current path leaves a dirty id without a page (ids enter the dirty
set only after the page is stored), so this is defensive rather than a
fix for observed loss.

The browser unit tests did not compile on wasm32 (a duplicate
page_cache_capacity from #341/#342, and dir_sync tests using tempfile);
both are fixed so the two new regression tests run.


Claude-Session: https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

perf: skip page cache allocation for BrowserDb (WASM/IndexedDB backend)

1 participant

0