fix(sqlite-native): gate native read cache behind env var#4630
Conversation
PR Review: fix(sqlite-native): gate native read cache behind env varSummary: This PR gates the native SQLite VFS read cache behind the RIVETKIT_SQLITE_NATIVE_READ_CACHE env var (disabled by default) to align native behavior with the WASM VFS, which has no read cache. Code Qualityread_cache_enabled() initialization (vfs.rs:106): Using a function-level static OnceLock is idiomatic and correct. The env var is read exactly once per process life and cached. Worth noting in a comment that this is intentionally process-scoped -- subsequent setenv calls after first initialization have no effect. Option pattern (vfs.rs:296): Clean representation. read_cache_enabled.then(HashMap::new) is idiomatic Rust. VfsContext.read_cache_enabled field (vfs.rs:155): Good decision to snapshot the flag at VFS creation rather than calling read_cache_enabled() per file open. Consistent across file handles opened through the same VFS instance. Minor IssueUnnecessary allocation in batch flush (vfs.rs:920): When read_cache is None, the dirty buffer is still collected into a Vec and then immediately dropped. Not a correctness issue (std::mem::take correctly clears the dirty buffer regardless), but it allocates on every atomic commit when caching is disabled. Suggested fix -- take the BTreeMap directly and skip the Vec: Test CoverageNo tests for the env var gating. Given that OnceLock makes env-var-based flags hard to test in parallel suites, this is understandable. A doc comment on read_cache_enabled() noting that it reads once at first call and subsequent env var changes are ignored would prevent future confusion. DocumentationThe env var RIVETKIT_SQLITE_NATIVE_READ_CACHE is undocumented outside the code. If this is user-facing (operators tuning performance), it should appear in the self-hosting configuration docs. If developer-only, the code comment is sufficient. CorrectnessThe change is correct. All cache interactions are properly guarded, and the no-cache path does not regress writes (data still goes through KV; the cache was purely an optimization). The WASM parity goal is achieved by defaulting the cache to disabled. Overall: Solid, focused change. The one actionable suggestion is removing the unnecessary Vec collect in the flush path by taking the BTreeMap directly. Everything else is clean and idiomatic. Generated with Claude Code |
a60a42d to
9d72e25
Compare
0f0530c to
7702123
Compare
9d72e25 to
2bb44ed
Compare
2bb44ed to
bf17632
Compare

Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: