Repository navigation
Journal sync receipts in IndexedDB instead of rewriting the whole batch - #26
Merged
Merged
Conversation
The SDK records a durable receipt after every applied action. Stores that implement appendJournal get one small event; others get a full rewrite of the mirror state, including every prepared document in the batch. The plugin's IndexedDB store never implemented it, so writes grew quadratically with the number of notes: a 1,000-note first sync wrote 3.0 GB (fake-indexeddb, 11.9 s) for a 0.5 MB checkpoint. IndexedDbMirrorStateStore now appends events under [key, "journal", n] in the same object store, replays them on read with the SDK's own applySyncJournalEvent, and drops them atomically on every full write and clear. The checkpoint summary is unaffected (events never change cursor, scope or batch presence). ReceiptObservingStateStore forwards appendJournal (the SDK detects it by presence) and reports receipts from journal events, loading the plan once for a batch resumed after restart. 1,000-note first sync: 3.0 GB -> 5.7 MB written, 11.9 s -> 0.39 s. The SDK patch exports applySyncJournalEvent/SyncJournalEvent from the mirror entry; proposed upstream.
Merged
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.
Fixes PERF-19 and most of PERF-5 from the overnight perf report.
Problem. The SDK records a durable receipt after every applied action. If the state store implements
appendJournal, it appends one small event; otherwise it rewrites the whole mirror state, including every prepared document in the batch. The plugin's IndexedDB store never implemented it, so a first sync's writes grew quadratically with the number of notes.Fix.
IndexedDbMirrorStateStoreappends events under[key, "journal", n]in the existing object store and replays them on read with the SDK's ownapplySyncJournalEvent. Every full write and clear drops them in the same transaction.ReceiptObservingStateStoreforwardsappendJournal(the SDK detects it by presence) and reports history from journal events, including for a batch resumed after a restart.applySyncJournalEventandSyncJournalEventfrom themirrorentry; a matching upstream PR follows.On real IndexedDB the "before" side is worse: every write is structured-cloned and flushed to disk.
Tests (
test/indexedDbJournal.test.ts, real SDK engine and real store):Full suite: 434 pass, plus 10 lossless round trips; lint and mobile check pass. No backwards compatibility is needed: unreleased.