Skip to content

Yield between inbound sync apply batches - #166

Open
marcus-pousette wants to merge 1 commit into
mainfrom
fix/remote-apply-scheduler
Open

Yield between inbound sync apply batches#166
marcus-pousette wants to merge 1 commit into
mainfrom
fix/remote-apply-scheduler

Conversation

@marcus-pousette

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

Copy link
Copy Markdown
Collaborator

What changed

  • Yield to one macrotask after applying each non-empty, non-final inbound opsBatch.
  • Keep batches sequential per filter, so completion and done markers cannot overtake earlier applies.
  • Add a regression proving a timer-scheduled user task runs before the next queued inbound apply.

Why

Without a scheduling gap, several already-queued remote batches can monopolize the worker event loop. A foreground read or write that arrives after one batch finishes is then forced to wait behind the next batch even though per-filter ordering does not require that starvation.

This does not make OPFS writes themselves faster. It makes queued sync work cooperative with foreground work.

Fast paths left

  • Empty batches and final/done batches do not add a yield.
  • Single-batch syncs pay no extra scheduling delay.
  • Verification, persistence, acknowledgements, and per-filter ordering are unchanged.
  • The existing queue remains the only serialization mechanism; this adds no scheduler state.

Debloat

The original PR was stacked on #164 and included 137 lines of runtime benchmark changes. Those benchmark files and the benchmark ancestry are removed. The review is now 3 files, +83/−1; 74 added lines are the timing/order regression.

Verification

  • @treecrdt/sync-protocol: 24/24 tests pass.
  • TypeScript build and git diff --check pass.

@marcus-pousette
marcus-pousette force-pushed the fix/remote-apply-scheduler branch from 48ab5ef to 7a95c36 Compare June 4, 2026 11:23
@marcus-pousette marcus-pousette added performance Measurable runtime, storage, or responsiveness improvement area:sync Sync protocol, reconciliation, transport, discovery, and sync servers area:web Browser, WASM, OPFS, workers, and playground runtime labels Jul 12, 2026
@marcus-pousette
marcus-pousette force-pushed the fix/remote-apply-scheduler branch from 7a95c36 to eee9e75 Compare July 12, 2026 13:44
@marcus-pousette marcus-pousette removed the area:web Browser, WASM, OPFS, workers, and playground runtime label Jul 12, 2026
@marcus-pousette
marcus-pousette changed the base branch from codex/runtime-perf-benchmark to main July 12, 2026 13:44
@marcus-pousette
marcus-pousette marked this pull request as ready for review July 12, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sync Sync protocol, reconciliation, transport, discovery, and sync servers performance Measurable runtime, storage, or responsiveness improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant