Skip to content

Drain the mutation queue without shifting the array - #4957

Open
Yahiro025 wants to merge 1 commit into
alpinejs:mainfrom
Yahiro025:fix-mutation-queue-drain
Open

Yahiro025 wants to merge 1 commit into
alpinejs:mainfrom
Yahiro025:fix-mutation-queue-drain

Conversation

@Yahiro025

Copy link
Copy Markdown

Updating a large x-for list queues one callback per DOM mutation and drains them with shift(). Once the array is large, each shift() copies the remaining entries, so the drain is quadratic; a 40,000-row update spends most of its time there.

flushObserver() and flushPendingMutations() now drain with an index and clear the array once. Callbacks queued while the drain runs are still executed in the same pass and in order.

tests/vitest/mutation-queue.spec.js queues 50,000 callbacks and fails if the drain shifts the queue. It fails on main.

Fixes #4952

This branch has not been deployed

No deployments
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.

Mutation queue drained with shift() is quadratic: updating a large x-for list is ~3× slower than needed

1 participant