Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Aug 13, 2025

This makes flushing effects much faster in scenarios where there's a lot of effects and many of them write to state.

We added this "bail and reschedule" mechanism mainly to prevent subsequent effects from being called when a prior effect execution did e.g. cause an if block to become false and the effect about to run next therefore being destroyed.

This change addresses that issue by flushing the newly created batch right away, but only executing its branches. Through this we also get rid of the false-positive loop protection error.

The one downside is that effect execution ordering is slightly different: Only things scheduled within the current batch are executed in order, all new (pre-)effects will run afterwards. The worst thing that can happen as a result is rerunning render or user effects more often than they need to, but I expect this to be minimal in comparison to the perf wins.

Fixes #16548

If we agree on the fix being sensible I'll adjust the tests, add some comments etc

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

This makes flushing effects much faster in scenarios where there's a lot of effects and many of the write to state.

We added this "bail and reschedule" mechanism mainly to prevent subsequent effects from being called when a prior effect execution did e.g. cause an if block to become false and the effect about to run next therefore being destroyed.

This change addresses that issue by flushing the newly created batch right away, but only executing its branches. Through this we also get rid of the false-positive loop protection error.

The one downside is that effect execution ordering is slightly different: Only things scheduled within the current batch are executed in order, all new (pre-)effects will run afterwards. The worst thing that can happen as a result is rerunning render or user effects more often than they need to, but I expect this to be minimal in comparison to the perf wins.

Fixes #16548
Copy link

changeset-bot bot commented Aug 13, 2025

⚠️ No Changeset found

Latest commit: e11e381

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@16612

@dummdidumm
Copy link
Member Author

dummdidumm commented Aug 17, 2025

closing in favor of #16631

@dummdidumm dummdidumm closed this Aug 17, 2025
@dummdidumm dummdidumm deleted the perf-and-infinite-loop-fix branch August 17, 2025 12:32
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.

Application using LayerChart hanging after updating Svelte to 5.36.0+ (logging UpdatedAtError in 3.36.5+)
1 participant