From cca8322ee2fef739e7fbf571df5d42bc58131dfe Mon Sep 17 00:00:00 2001 From: serversdown Date: Sun, 21 Jun 2026 05:12:13 +0000 Subject: [PATCH] =?UTF-8?q?perf:=20WAL=20synchronous=3DNORMAL=20=E2=80=94?= =?UTF-8?q?=20stop=20fsyncing=20every=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lyra.db is on disk-backed ext4, where each WAL commit fsync'd (~0.15s here). Every chat turn does several writes (remember user+assistant, summaries, poker logging), so this was adding real per-turn latency, and made the dream loop + tests crawl. synchronous=NORMAL is WAL's recommended companion: durable across app crashes, only a power/OS crash can drop the last txn (never corrupts). Per-write dropped from ~0.4s to ~0.001s; test suite 72s -> 24s. Co-Authored-By: Claude Opus 4.8 (1M context) --- lyra/memory.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lyra/memory.py b/lyra/memory.py index 0529612..a7a3478 100644 --- a/lyra/memory.py +++ b/lyra/memory.py @@ -131,6 +131,11 @@ def _connection() -> sqlite3.Connection: # alongside the web server without tripping "database is locked". _conn.execute("PRAGMA busy_timeout=5000") _conn.execute("PRAGMA journal_mode=WAL") + # WAL's recommended companion: don't fsync on every commit (only at + # checkpoint). Safe against app crashes; a power/OS crash can lose the last + # txn but never corrupt. On disk-backed storage this turns ~0.15s-per-commit + # fsync latency into ~nothing — big win for per-turn writes + the dream loop. + _conn.execute("PRAGMA synchronous=NORMAL") _conn.executescript(SCHEMA) # Migrations for DBs created before a column existed (no-op if present). for ddl in ("ALTER TABLE sessions ADD COLUMN mode TEXT",):