Repository navigation
perf(sync): keep checksum only on remote graphs - #13476
Merged
tiensonqin merged 1 commit intoSep 30, 2026
Merged
Conversation
This was referenced Sep 27, 2026
Closed
tiensonqin
approved these changes
Sep 30, 2026
After every transaction the db listener updates the sync checksum and stores it, with the tx it covers, in the graph's client-ops database: 2 synced sqlite commits per edit, on every graph. That checksum is only compared with the sync server's, and a graph's first upload recomputes it in full before it sends the snapshot, so on a graph that does not sync the work has no reader. Keep the stored checksum only on a graph whose :logseq.kv/graph-remote? is true (upload and download set it). On other graphs update-local-sync-checksum! returns before it reads or writes, and reconcile-local-checksum! does not recompute at open, which would otherwise redo the whole checksum at every open of a local graph that still holds an old stored value. The transaction that makes a graph remote starts from a full recompute instead of the stored value, which may predate edits made while the graph was local. On a remote graph nothing changes. The tests that check the stored checksum on a synced path now mark their graph remote.
tiensonqin
force-pushed
the
perf/checksum-local-graphs
branch
from
September 30, 2026 03:50
c5a054e to
b4993e7
Compare
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Sep 30, 2026
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Sep 30, 2026
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 1, 2026
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 4, 2026
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 8, 2026
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 11, 2026
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 13, 2026
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 16, 2026
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
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 updates the sync checksum and stores it, with the tx it covers, in the graph's client-ops database (
update-local-sync-checksum!insrc/main/frontend/worker/sync.cljs, 2 synced sqlite commits throughclient-op/update-local-checksum). It does this on every graph, also on one that never syncs. On such a graph nothing uses the value:verify-sync-checksum!insync/handle_message.cljs(dev and test builds, on a sync connection). The rest of its uses keep it current: the next incremental update, and the check at open (reconcile-local-checksum!), which recomputes it when a write was lost.upload-graph!insync/upload.cljsrecomputes the checksum in full, stores that, and sends it with the last snapshot batch.db-sync-statusthread API (the CLI'ssync status) and the developer checksum diagnostics, which return a recomputed value.With this change the stored checksum is kept only on a graph whose
:logseq.kv/graph-remote?is true. Upload and download set that flag (set-graph-sync-metadata!insync/upload.cljsandsync/download.cljs), nothing unsets it, and it is already howhandle-local-tx!(asset sync) and the built-in sync repair indb_core.cljstell a synced graph.update-local-sync-checksum!returns before any read or write on a graph that is not remote after the transaction.reconcile-local-checksum!returns on a graph that is not remote. Without this, a local graph that still holds a checksum from an earlier version would get a whole-graph recompute at every open, since its covered tx no longer follows the graph.:logseq.kv/graph-rtc-e2ee?for the first time, andupdate-checksumalready recomputes in full when that flag changes, so an upload runs as many recomputes as before (1 in the listener, 1 inupload-graph!). In a download, the import batches before the one that carries the flag leave the checksum alone, and that batch starts from a full recompute.Left as it is:
db-sync-statuson a graph that does not sync returns what was stored before (nil on a new graph).start!can connect sync to a graph without the flag when a remote graph has the same name (<resolve-start-graph-id); such a graph keeps no checksum now, which shows in the status output and in the dev-build compare log only, and asset sync already treats it as local.Measured on the desktop app, release builds of master (
16c4ed1a0) and this branch, a new graph without sync, 30 cycles per session, median (range), key to the next editor focused (delete) or to the editor gone (save):#13470 is complementary: it makes the checksum write 1 synced commit instead of 2 on graphs that sync, where this change keeps the write.
Tests
frontend.worker.db-sync-test:local-graph-edit-writes-no-checksum-test: an edit on a local graph writes no checksum and no covered tx. On master it fails (3 failures: 1 write, both stored).local-graph-open-does-not-recompute-checksum-test: the open-time check on a local graph with a lagging stored checksum recomputes nothing and leaves the stored values. On master it fails (3 failures: 1 recompute, both replaced).graph-becoming-remote-starts-from-full-checksum-test: the transaction that marks a graph remote, without an E2EE flag change, stores a full recompute. On master it fails (1 failure: the old value stays).remote-graph-edit-writes-checksum-test: an edit on a remote graph still writes once, a value equal to a full recompute, with the graph's:max-tx. Passes on master too.upload-after-local-edits-stores-and-sends-full-checksum-test:upload-graph!with its network calls replaced, after a local edit that did not update the stored checksum, stores and sends a checksum equal to a full recompute. Passes on master too.frontend.worker.db-sync-testand 5 infrontend.worker.db-sync-sim-testcheck the stored checksum along synced paths (rebase, reject,pull/ok, batch reports, undo and redo, the open-time check) on graphs built without the flag. They now build remote graphs (mark-graph-remote!,create-remote-conn), as those paths run on in the app. Without that they fail with this change (14 and 11 failures).frontend.worker.db-sync-test238 tests, 2238 assertions;frontend.worker.db-sync-sim-test22 tests, 433 assertions;frontend.worker.db-listener-test14 tests, 51 assertions;frontend.worker.sync.client-op-test6 tests, 22 assertions;frontend.worker.sync.upload-test10 tests, 33 assertions;logseq.db-sync.checksum-test(run fromdeps/db-sync) 28 tests, 78 assertions: 0 failures, 0 errors.TZ=Etc/GMT+12(2507 tests, 12513 assertions) and its time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1474 tests, 9072 assertions): 0 failures, 0 errors.Allow edits from maintainers.