Repository navigation
perf(sync): write the checksum in 1 transaction - #13470
Closed
yuxi-liu-wired wants to merge 1 commit into
Closed
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
After every graph commit the checksum and the tx it covers were 2 sqlite autocommits on the client-ops database, each a synced write. Write both in 1 transaction.
This was referenced Sep 27, 2026
This was referenced Sep 30, 2026
Contributor
Author
This was referenced Sep 30, 2026
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.
What changes
After every transaction, the db listener stores the new sync checksum and the tx it covers in the graph's client-ops database (
update-local-checksum,src/main/frontend/worker/sync/client_op.cljs). The 2 keys went in 2 upserts, each its own sqlite autocommit. That database runs in WAL mode withsynchronousFULL (read withPRAGMA synchronouson a graph's client-ops file), so each autocommit is a synced write. The 2 upserts now run in 1 transaction throughsqlite-with-tx!, which the file already has, so each transaction pays 1 synced commit, and the 2 keys change together.In the node worker,
sqlite-with-tx!calls the connection wrapper'stransaction(wrap-node-sqlite-dbinsrc/main/frontend/worker/platform/node.cljs), which runs the function betweenBEGINandCOMMIT.Timings on a graph of 157,614 checksum-eligible entities (imported from a file graph), standalone db worker, median (range) of 3 runs per build:
update-checksumplus the write), which the dev build logs, master against this change: 1-block insert 17.5 ms (17.0 - 17.8) against 10.0 ms (9.4 - 10.0), 1-block move 17.2 ms (16.4 - 25.0) against 9.2 ms (8.5 - 10.0), 1-block delete 17.2 ms (16.4 - 19.9) against 9.6 ms (9.2 - 10.3), 200-block insert 34.8 ms (33.7 - 36.6) against 28.2 ms (26.1 - 29.3), 200-block delete 33.1 ms (32.7 - 36.2) against 25.0 ms (24.6 - 27.4). The first transaction after the start, a 1-block save, takes 18.0 ms (17.2 - 24.0) on master and 17.7 ms (17.0 - 18.7) with this change.The builds with this change also carried the commits of
perf/checksum-one-walkandfix/restore-max-txand 1 change to the sqlite read path. A build with the recompute changes and without this commit wrote in 16.8 ms (16.2 - 17.1) release and 17.2 ms (16.6 - 17.6) dev, 3 runs each, the same as master.Tests
checksum-and-covered-tx-written-in-1-transaction-testinfrontend.worker.sync.client-op-test: counts the calls of the database'stransactionduringupdate-local-checksumand reads both keys back. On master it fails (1 failure: 0 calls). With this change it passes. The test's database is better-sqlite3 in memory, as in the rest of that namespace.frontend.worker.sync.client-op-test7 tests, 25 assertions;frontend.worker.db-sync-test233 tests, 2222 assertions;logseq.db-sync.checksum-test(run fromdeps/db-sync) 28 tests, 78 assertions: 0 failures.TZ=Etc/GMT+12(2503 tests, 12500 assertions) and its time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1469 tests, 9056 assertions): 0 failures, 0 errors.Allow edits from maintainers.