perf: coalesce auto-save serialization while a write is in flight - #90
Open
imurashka wants to merge 4 commits into
Open
perf: coalesce auto-save serialization while a write is in flight#90imurashka wants to merge 4 commits into
imurashka wants to merge 4 commits into
Conversation
While the previous snapshot is still on its way to the disk, a change no longer serializes the whole storage: it only marks the storage as changed. The background writer asks the storage to serialize once more when it becomes free, through the SynchronizationContext captured at build time.
…orage Look up a registered section through a type-to-index dictionary instead of scanning the section list twice with two different comparisons. Share the type-mismatch decision between Set and SetRaw, and keep reactive collection tracking in one pair of methods instead of five copies. Hand the deferred-save callback to the writer at construction so it stops travelling through a settable property on three types, and move the test-only AddRange helpers out of the runtime assembly.
ReactiveList, ReactiveSet and ReactiveDictionary each carried their own copy of the dispose flag, the OnChanged event, SetDirty and ThrowIfDisposed. Move that contract into ReactiveCollection so a change to it lands in one place. Build the nested storage key list in a single pass instead of a LINQ chain, and reuse the prefix check that RemoveAll already needed.
MarkChanged, DecreaseCounter and SaveDeferredChanges each carried their own copy of the "auto-save is on, no change scope is open, there is something to save" condition. Route the other two through MarkChanged so the policy lives in one method. Give the nested storage key list its capacity up front and reuse a cached prefix predicate, post the deferred-save callback through a static callback instead of a closure, and share one storage-opening helper across the persistence fixtures.
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.
Auto-save no longer serializes the whole storage on every change. While the previous snapshot is still on its way to the disk, a change only marks the storage as changed; the background writer asks the storage to serialize once more when it becomes free, through the
SynchronizationContextcaptured when the storage was built.A burst of 200
Setcalls now costs one serialization instead of 200. Measured in the editor on Windows: 54 keys 2.05 ms -> 0.02 ms, 1 710 keys 49.22 ms -> 0.01 ms, 16 200 keys 457.88 ms -> 0.01 ms. Serialization still happens on the thread that owns the storage, so nothing new is read from another thread. A storage built without aSynchronizationContextkeeps serializing on every change, exactly as before.