Prioritize foreground reads during background sync#167
Draft
marcus-pousette wants to merge 2 commits into
Draft
Conversation
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 changed
applyOpsappends as background work.This is stacked on #166. It builds on the batch-level yield there: #166 creates a scheduling gap between inbound sync batches; this PR decides what should run in that gap.
Performance Results
Measured on shared-worker OPFS with real
SyncPeer.pushOpsingest, 2,000 remote ops, 500-op remote batches, 20 local writes, and 20 paginated reads usingchildrenPage(root, null, 50).036.70ms37.00ms38.45ms1422ms06.70ms6.83ms151.31ms40.37ms1561ms5k160.16ms3.07ms347.27ms7488ms5k5.61ms5.22ms400.82ms369.54ms8503ms10k602.83ms40.27ms1067.58ms570.89ms13575ms10k5.96ms4.90ms563.58ms562.56ms12906msThe main improvement is the specific read scheduled immediately after a remote batch:
160ms -> 5.6msat 5k prefill and603ms -> 6msat 10k prefill. This does not make a runningappendManybatch interruptible, so read p95 can still be high when a read lands behind an active batch or normal write.