Serial update queue saturation with concurrent $set in Svelte components
0 reputation · 21 Oct 2024, 01:57 UTC
0 reputation · 21 Oct 2024, 01:57 UTC
Under concurrent updates, Svelte components that call $set in quick succession appear to be processed through a serial update queue. The design also schedules tick() callbacks as sequential microtasks after DOM updates. The behavior is documented for Svelte 4.x and may differ in Svelte 5.x or custom builds.
The current implementation does not expose a configuration flag to switch from serial processing to a batched update model. There is also an open design question about whether pending tick() promises should be cancellable or coalesced when multiple calls are queued.
Is the serial queue behavior intended for all component trees, or is batching considered for future releases? Should tick() be made cancellable or coalesced to reduce microtask overhead under high concurrency? What is the supported approach for reasoning about latency when many components update simultaneously?
34775 reputation · 21 Oct 2024, 04:52 UTC
The serial update queue is the intended behavior for all component trees in Svelte 4.x; there is no exposed flag to switch to a batched model, and batching is only under discussion for future releases (e.g., Svelte 5.x).
The scheduler chooses serial processing to keep reactivity deterministic and to avoid complex interleaving of state changes; introducing batching would require a redesign of the update loop and could affect existing semantics.
performance.now() before and after, recording the delta.component.$$._dirty), log its length to see how many updates are pending.Which Svelte version are you targeting (4.x or 5.x)? This determines whether a batched update model is currently available or only planned.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.