Skip to content

perf(db,startup): WAL checkpoint, synchronous=NORMAL, memoized stats, dead-asset removal - #59

Merged
JeanBaptisteRenard merged 1 commit into
mainfrom
perf/db-and-startup-quick-wins
Jun 11, 2026
Merged

perf(db,startup): WAL checkpoint, synchronous=NORMAL, memoized stats, dead-asset removal#59
JeanBaptisteRenard merged 1 commit into
mainfrom
perf/db-and-startup-quick-wins

Conversation

@JeanBaptisteRenard

Copy link
Copy Markdown
Collaborator

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 changes snippet() behavior and needs review).

Changes (all mechanical, audit refs Q1/Q6/Q10/Q5/Q7)

  • Q1 closeDb() runs wal_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.
  • Q6 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).
  • Q10 the four stats queries (getDailyMetrics, getDailyModelTokens, getModelUsage, getTotalCounts) re-parsed SQL on each call — now memoized on first use.
  • Q5 delete public/icon.png (275 KB): shipped in every build via files: public/**, referenced nowhere (window icon is build/icon.png).
  • Q7 call 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 check green — 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).

…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)
@JeanBaptisteRenard
JeanBaptisteRenard merged commit fbaf013 into main Jun 11, 2026
7 checks passed
@JeanBaptisteRenard
JeanBaptisteRenard deleted the perf/db-and-startup-quick-wins branch June 11, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant