From bd0490235129de90c60b72ff5310578e1f712cc7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 14:35:23 +0000 Subject: [PATCH] perf(shared): SQLite catches up the WAL only after a checkpoint leaves frames behind The checkpoint worker ran a full catch-up after every 100 ms pause in writes, even when no threshold checkpoint had run since the WAL last restarted. Streaming turns pause that often, so the same hot pages were copied into the database (with F_FULLFSYNC on macOS) about 130 times a minute. The catch-up now waits until a checkpoint has backfilled part of the WAL, which is the only time the WAL cannot restart on its own. Fixes pingdotgg/t3code#38159 Co-Authored-By: Claude Opus 5.5 --- packages/shared/src/nodeSqliteClient.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/nodeSqliteClient.ts b/packages/shared/src/nodeSqliteClient.ts index 51e47c4bb5530..9c6dec650f665 100644 --- a/packages/shared/src/nodeSqliteClient.ts +++ b/packages/shared/src/nodeSqliteClient.ts @@ -664,10 +664,11 @@ const check = (force) => { passive.get(); state = frames.get(); } - // The WAL restarts only once every frame is checkpointed, so catch up when writes pause. + // The WAL restarts only once every frame is checkpointed, so after a checkpoint leaves frames + // behind, catch up when writes pause. Before any checkpoint, wait for the frame threshold. // A reader pinning the WAL stops progress; the next write retries instead of a timer loop. const progressed = !force || state.checkpointed > before.checkpointed; - if (state.log > state.checkpointed && progressed) { + if (state.checkpointed > 0 && state.log > state.checkpointed && progressed) { idle = setTimeout(() => run(true), workerData.idleMs); } parentPort.postMessage({ type: "checked", log: state.log, checkpointed: state.checkpointed });