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 unless a small explicit exception applies.
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
+
- Preserve page 1 handling unless we explicitly decide to make it configurable later.
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 the read pages from the speculative 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
+
- Page 1 should remain retained for now because it carries page size and database size metadata and is already special-cased throughout the VFS.
37
+
- Protected cache should no longer protect arbitrary early speculative pages forever. It should either be limited to page 1 or removed in favor of the TTL cache.
Copy file name to clipboardExpand all lines: docs-internal/engine/SQLITE_OPTIMIZATIONS.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,8 @@ 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 speculative startup preload and read-ahead pages. Direct target pages fetched for `xRead` are not retained after SQLite receives them; speculative entries are invalidated on first target read and also expire through `RIVETKIT_SQLITE_OPT_VFS_STAGING_CACHE_TTL_MS`.
15
+
- VFS staging cache behavior is selected with `RIVETKIT_SQLITE_OPT_VFS_PAGE_CACHE_MODE=off|target|startup|prefetch|all`, with capacity and page-1 protected-cache behavior configured separately.
15
16
- 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
17
- 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
18
- Actor Prometheus metrics expose VFS read counters, fetched bytes, cache hits/misses, and `get_pages` duration at `/gateway/<actor_id>/metrics`.
0 commit comments