From 6601616d7adc3a3b5732b49f1c56f13abfd1bac8 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 1 Oct 2026 11:48:33 -0700 Subject: [PATCH] sqlite storage: wrap store batch in a single transaction sqlite3_exec commits each statement in its own implicit transaction, so a bulk store of N entries costs N fsync-bound commits. Wrapping the upsert batch in BEGIN IMMEDIATE/COMMIT collapses it to one commit. --- examples/logseq_sqlite_storage.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/logseq_sqlite_storage.ml b/examples/logseq_sqlite_storage.ml index 7eefc9d..c859da8 100644 --- a/examples/logseq_sqlite_storage.ml +++ b/examples/logseq_sqlite_storage.ml @@ -1321,7 +1321,10 @@ let storage db_path = create_kvs_table db_path; let store entries = let sql = String.concat "" (List.map upsert_sql entries) in - if sql <> "" then exec_sql db_path sql + (* Without an explicit transaction sqlite3_exec commits every + statement separately — thousands of fsyncs on a bulk store. + One transaction costs one commit's worth of syncs. *) + if sql <> "" then exec_sql db_path ("begin immediate;" ^ sql ^ "commit;") in let restore address = let addr = sqlite_addr_of_storage_address address in