perf(db,startup): WAL checkpoint, synchronous=NORMAL, memoized stats, dead-asset removal - #59
Merged
Merged
Conversation
…ed stats statements, drop dead asset Audit findings (2026-06-11, .work-files broad-audit-summary): - the -wal file had grown to 39 MB (long-lived scan-worker readers starve automatic checkpoints): closeDb now runs wal_checkpoint(TRUNCATE) - synchronous defaulted to FULL, which fsyncs every write for no extra integrity in WAL mode → NORMAL (standard WAL pairing) - the four stats queries re-parsed their SQL on every stats-screen open → memoized on first use - public/icon.png (275 KB) was shipped in every build but referenced nowhere (the window icon uses build/icon.png) - cleanStaleLockFiles was imported in main.js but never called → invoked at startup (it only unlinks Switchboard locks matching our own pid)
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.
Audit quick wins (independent of the renderer-memory stack #55-#58)
From the broad perf audit (
.work-files/switchboard/mem-opt-go-sidecar/broad-audit-summary.md). DB measured at 193 MB + 39 MB WAL never checkpointed; FTS5 tables are 97% of the file (that bigger fix — contentless FTS + body truncation, est. 193→~40 MB — is intentionally NOT in this PR, it changessnippet()behavior and needs review).Changes (all mechanical, audit refs Q1/Q6/Q10/Q5/Q7)
closeDb()runswal_checkpoint(TRUNCATE)before close — the scan worker's long-lived reader connection starves automatic checkpoints, so the WAL grows unbounded between runs (witnessed 39 MB) and adds read amplification on every query.synchronous = NORMAL— the standard WAL pairing; FULL fsyncs every write for no extra integrity in WAL mode (corruption-safe either way; at most the last transactions roll back on power loss).getDailyMetrics,getDailyModelTokens,getModelUsage,getTotalCounts) re-parsed SQL on each call — now memoized on first use.public/icon.png(275 KB): shipped in every build viafiles: public/**, referenced nowhere (window icon isbuild/icon.png).cleanStaleLockFiles(log)at startup — imported since the MCP bridge landed but never invoked; it only unlinks Switchboard IDE locks matching our own pid (crash + PID-reuse leftovers).Verification
task checkgreen — 195/195, 0 lint errors. WAL truncation takes effect at next clean quit; safe while an instance is running (this PR does not rebuild native modules).