Skip to content

Prioritize foreground reads during background sync#167

Draft
marcus-pousette wants to merge 2 commits into
fix/remote-apply-schedulerfrom
fix/shared-worker-priority-scheduler
Draft

Prioritize foreground reads during background sync#167
marcus-pousette wants to merge 2 commits into
fix/remote-apply-schedulerfrom
fix/shared-worker-priority-scheduler

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • Adds RPC priority metadata plus foreground/background scheduling to wa-sqlite worker clients and the shared worker.
  • Marks inbound sync applyOps appends as background work.
  • Routes read/query APIs as foreground work so they can run between background sync apply batches.
  • Keeps local writes in the normal lane so they do not overtake an active background sync stream.
  • Updates the runtime benchmark to exercise background remote sync applies.
  • Adds shared OPFS e2e coverage for applying remote batches around an interleaved local write.

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.pushOps ingest, 2,000 remote ops, 500-op remote batches, 20 local writes, and 20 paginated reads using childrenPage(root, null, 50).

Prefill Branch Inter-batch read Read p50 Read p95 Local write p50 Total duration
0 #166 baseline 36.70ms 37.00ms n/a 38.45ms 1422ms
0 this PR 6.70ms 6.83ms 151.31ms 40.37ms 1561ms
5k #166 baseline 160.16ms 3.07ms n/a 347.27ms 7488ms
5k this PR 5.61ms 5.22ms 400.82ms 369.54ms 8503ms
10k #166 baseline 602.83ms 40.27ms 1067.58ms 570.89ms 13575ms
10k this PR 5.96ms 4.90ms 563.58ms 562.56ms 12906ms

The main improvement is the specific read scheduled immediately after a remote batch: 160ms -> 5.6ms at 5k prefill and 603ms -> 6ms at 10k prefill. This does not make a running appendMany batch interruptible, so read p95 can still be high when a read lands behind an active batch or normal write.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant