You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This plan changes the SQLite VFS page cache from a broad second-level pager cache into a short-lived staging cache for speculative pages. Demand pages fetched for `xRead` should be handed to SQLite and then forgotten by the VFS.
6
+
7
+
## Goals
8
+
9
+
- Avoid retaining pages in VFS memory after SQLite has already received them through `xRead`.
10
+
- Keep startup preload and read-ahead useful by retaining speculative pages briefly.
11
+
- Evict speculative pages on first successful target read so TTL is only the fallback for unused preloads.
12
+
- Keep lazy loading correct when all cache and preload features are disabled.
13
+
- Treat page 1 as staging data after `xRead` while keeping parsed page-size and database-size metadata.
14
+
15
+
## Non-Goals
16
+
17
+
- Do not change the remote `get_pages` protocol.
18
+
- Do not change SQLite pager settings.
19
+
- Do not add read pools back.
20
+
- Do not implement persisted preload hints in this branch.
21
+
22
+
## Current Behavior
23
+
24
+
-`resolve_pages` classifies fetched pages as `Target` when SQLite requested them and `Prefetch` when they were predicted.
25
+
-`fetch_initial_pages_for_registration` seeds startup pages as `Startup`.
26
+
-`should_cache_page` allows target, prefetch, and startup caching based on `SqliteVfsPageCacheMode`.
27
+
- Page 1 is always cacheable.
28
+
- Early protected pages live in `protected_page_cache`, which is an `scc::HashMap` with no TTL.
29
+
30
+
## Proposed Behavior
31
+
32
+
- Target pages should not be inserted into the VFS page cache by default.
33
+
- Target reads should remove speculative read pages from the cache after bytes are copied to the caller.
34
+
- Prefetch pages should be inserted into a TTL cache.
35
+
- Startup preload pages should be inserted into the same TTL cache.
36
+
- Commit completion should stage dirty pages in a separate TTL cache so SQLite can reread its own writes without retaining them permanently.
37
+
- Page 1 should follow the same staging rule as other pages after `xRead`. The VFS keeps parsed page-size and database-size metadata, and it can synthesize the empty page-1 header again before the first commit when depot has no database yet.
38
+
- Protected cache should no longer protect speculative pages forever. It should be removed or left unused in favor of the TTL cache.
Copy file name to clipboardExpand all lines: docs-internal/engine/SQLITE_OPTIMIZATIONS.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,10 @@ Range page-read protocol details live in `.agent/specs/sqlite-range-page-read-pr
11
11
## Existing Optimizations
12
12
13
13
- Actor startup can preload SQLite VFS pages through `OpenConfig.preload_pgnos`, `OpenConfig.preload_ranges`, and persisted `/PRELOAD_HINTS`; first pages, hint mechanisms, and the preload byte budget are configured through central SQLite optimization flags.
14
-
- The VFS keeps an in-memory page cache seeded from `sqlite_startup_data.preloaded_pages`; cache behavior is selected with `RIVETKIT_SQLITE_OPT_VFS_PAGE_CACHE_MODE=off|target|startup|prefetch|all`, with capacity and protected-cache budget configured separately.
14
+
- The VFS keeps a short-lived staging cache for startup preload and read-ahead pages. Direct target pages fetched for `xRead` are not retained in VFS memory.
15
+
- Any speculative page consumed by `xRead`, including page 1, is evicted from the VFS staging cache after SQLite receives it. Before the first commit, a lazy page-1 read for a missing database synthesizes the empty SQLite header again instead of retaining page bytes. Staged pages that SQLite never reads expire through `RIVETKIT_SQLITE_OPT_VFS_STAGING_CACHE_TTL_MS`.
16
+
- Commit completion stages dirty pages in a separate TTL cache so SQLite can reread its own writes without turning the VFS into a permanent second pager.
17
+
- VFS staging cache behavior is selected with `RIVETKIT_SQLITE_OPT_VFS_PAGE_CACHE_MODE=off|target|startup|prefetch|all`, with capacity configured separately. The protected-cache budget no longer pins VFS page bytes beyond `xRead`.
15
18
- The VFS has speculative read-ahead selected with `RIVETKIT_SQLITE_OPT_READ_AHEAD_MODE=off|bounded|adaptive`; the default bounded budget is 64 pages, which reduced the cold-read benchmark from 1,249 to 368 VFS `get_pages` calls.
16
19
- The VFS tracks bounded recent page hints as hot pages plus coalesced scan ranges; `NativeDatabase::snapshot_preload_hints()` exposes the in-memory plan for future flush wiring.
17
20
- Actor Prometheus metrics expose VFS read counters, fetched bytes, cache hits/misses, and `get_pages` duration at `/gateway/<actor_id>/metrics`.
0 commit comments