perf(state): config-gated SQLite PRAGMA tuning for large DBs (salvage #71755) - #77630
Merged
kshitijk4poor merged 3 commits intoAug 3, 2026
Merged
Conversation
kshitijk4poor
enabled auto-merge (rebase)
August 3, 2026 11:59
kshitijk4poor
force-pushed
the
salvage/71755-pragma-tuning
branch
from
August 3, 2026 13:13
38fd2f7 to
75b18e9
Compare
|
Code Review: #77630 Verdict: Approve DB PRAGMAs: well-documented addition of cache_size, mmap_size, temp_store. Safe best-effort. LGTM - Reviewed diff. Changes are sound. |
…agmas Addresses review from @teknium1 on PR NousResearch#71755: - Extended apply_database_pragmas() to handle cache_size, mmap_size, and temp_store from config.yaml (alongside existing wal_autocheckpoint and journal_size_limit). No hardcoded defaults — all values are opt-in via config.yaml, avoiding policy conflicts with other PRs. - Applied to ALL connection types: writer (_connect_and_init), read_only cross-profile attach, and WAL per-thread readers (_get_read_conn). Previously PRAGMAs only ran on the writer path. - Removed inline PRAGMAs from _connect_and_init — single source of truth in apply_database_pragmas(). - Documented config keys with examples in function docstring.
…ection types E2E guard for the salvaged PR NousResearch#71755: database.cache_size/mmap_size/ temp_store from config.yaml must reach the writer connection, the read-only cross-profile attach, and the WAL per-thread reader — and a default install (no database: keys) must keep byte-identical SQLite defaults on every connection type. Also covers integer-coercion rejection of garbage values for the three new keys. cache_size uses -16000 (not the doc example -2000) because -2000 is SQLite's compiled-in default and would not discriminate a regression.
kshitijk4poor
force-pushed
the
salvage/71755-pragma-tuning
branch
from
August 3, 2026 14:38
75b18e9 to
dff7eb0
Compare
3 tasks
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.
Context
Users with large state.dbs (hundreds of MB — heavy browser/tool sessions) can only tune SQLite via
wal_autocheckpoint/journal_size_limittoday. This adds three config-gated, non-durability pragmas —database.cache_size,database.mmap_size,database.temp_store— and applies the pragma pass to the read-only connection and the per-thread WAL readers (cache_size/mmap_size are per-connection, so readers never benefited before). WHO benefits: opt-in only — users who set these keys in config.yaml, i.e. large-DB power users; a default install is byte-for-byte unchanged.Measured impact
211 MB synthetic DB (360k rows), heavy read scan, default page cache vs
cache_size=-262144+ 256 MB mmap, median of 5:Honest caveat: config-gated and default-off; the win only exists for users who opt in on a large DB, and is workload-dependent (warm repeated reads benefit most; cold I/O-bound scans barely move).
Safety audit (the #64091 lesson)
No durability pragmas: the allowlisted tuple gains only
cache_size,mmap_size,temp_store— nosynchronous,journal_mode,locking_mode, orfullfsync. Values apply ONLY when present in config.yaml; integer coercion warns-and-skips garbage;apply_database_pragmasremains best-effort try/except so a failing pragma cannot break open. The docstring's journal-mode-ownership warning stays accurate. Per-reader cost is bounded: the reader connection is thread-local, so the pragma pass runs once per thread lifetime, and the config read is the mtime-cached fast path.Provenance
Salvage of #71755 by @crayfish-ai (both commits authorship-preserved). Follow-up commit adds the missing guard test: config-set pragmas must reach the writer, read-only, and per-thread reader connections (with a discriminating
-16000vs SQLite's-2000default so a revert can't accidentally pass), and a no-config run must leave defaults untouched. Mutation-checked: reverting the pragma wiring turns the test RED.Verification
-p no:randomly) + the new end-to-end pragma test.Closes #71755.