Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: optimise effects #11569

Merged
merged 8 commits into from May 12, 2024
Merged

chore: optimise effects #11569

merged 8 commits into from May 12, 2024

Conversation

Rich-Harris
Copy link
Member

Noticed this while reviewing recently merged PRs. @dummdidumm realised in https://github.com/sveltejs/svelte/pull/11560/files#r1597502682 that we're doing unnecessary work in a loop.

It turns out we can go further — we don't need the filter_flags & EFFECT stuff at all, because effects only contains effects with that flag. And since the only time we don't want to process effects recursively is inside flush_local_render_effects (when EFFECT effects are excluded), these two conditions are in fact synonymous:

if ((filter_flags & EFFECT) !== 0) {...}
if (!shallow) {...}

And shallow is only used negatively, so rather than doing !shallow everywhere we should save ourselves the unnecessary instruction by doing recursive instead.

The resulting code is somewhat clearer in my eyes.

Copy link

changeset-bot bot commented May 12, 2024

🦋 Changeset detected

Latest commit: 691145c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member Author

It looks like all the filter_flags stuff is unnecessary? At the very least, removing it doesn't cause any tests to fail

@Rich-Harris
Copy link
Member Author

In fact, if we remove flush_local_render_effects (which is only used inside the legacy beforeUpdate) altogether, the tests still pass. So one of two things is true:

  • there are some opportunities for further simplification
  • we are lacking some tests

@Rich-Harris Rich-Harris changed the title optimise effects chore: optimise effects May 12, 2024
@Rich-Harris
Copy link
Member Author

Opened #11570 on top of this

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.

None yet

2 participants