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.
I have always hated this code. It's been a bug magnet in the past, and is very confusing and convoluted. The rationale for it was that it's better for performance/memory to hoist these functions, but it feels like a flimsy justification — if it matters enough for event handlers that we need to jump through these hoops, we should be doing it for all functions.
More to the point, it just doesn't appear to be true. In my local testing, I can't observe any performance difference whatsoever between this branch and
mainwhen it comes to initialization. It would be hard to construct a test that measured the cost of actually running the handlers but it doesn't matter because event handlers are, almost by definition, not hot code paths.As for memory, my measurements indicate that the hoisted functions actually cost more than the non-hoisted ones. Arrays aren't free.
My understanding is that the performance benefits come from not having to register an event handler on each element (where even if you're using the same handler function on every element, a new object gets created each time), not from the deduplication. So we should just get rid of this.
Why now? I'm investigating some changes to the compiler that would enable out-of-order rendering (to get rid of more async waterfalls) and I just do not have the patience to work around this stuff.
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint