Skip to content

Commit b441738

Browse files
Rich-Harristrueadm
andauthored
chore: improve performance of scheduling effects (but without creating additional branches) (#13300)
* fix: improve performance of scheduling effects * alternative fix * add comment * use same codepath * use same codepath * address feedback * tweak * more tweaks * more tweaks * address feedback * remove EFFECT_HAS_DIRTY_CHILDREN * revert * mark effect root as queued instead of adding a branch effect * revert * revert * unused * revert --------- Co-authored-by: Dominic Gannaway <[email protected]>
1 parent dbc5793 commit b441738

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

.changeset/fresh-houses-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: improve performance of scheduling effects

packages/svelte/src/internal/client/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const EFFECT_TRANSPARENT = 1 << 15;
1818
export const LEGACY_DERIVED_PROP = 1 << 16;
1919
export const INSPECT_EFFECT = 1 << 17;
2020
export const HEAD_EFFECT = 1 << 18;
21+
export const EFFECT_QUEUED = 1 << 19;
2122

2223
export const STATE_SYMBOL = Symbol('$state');
2324
export const STATE_SYMBOL_METADATA = Symbol('$state metadata');

packages/svelte/src/internal/client/runtime.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
BLOCK_EFFECT,
2323
ROOT_EFFECT,
2424
LEGACY_DERIVED_PROP,
25-
DISCONNECTED
25+
DISCONNECTED,
26+
EFFECT_QUEUED
2627
} from './constants.js';
2728
import { flush_tasks } from './dom/task.js';
2829
import { add_owner } from './dev/ownership.js';
@@ -511,6 +512,10 @@ function flush_queued_root_effects(root_effects) {
511512
for (var i = 0; i < length; i++) {
512513
var effect = root_effects[i];
513514

515+
if ((effect.f & EFFECT_QUEUED) !== 0) {
516+
effect.f ^= EFFECT_QUEUED;
517+
}
518+
514519
// When working with custom elements, the root effects might not have a root
515520
if (effect.first === null && (effect.f & BRANCH_EFFECT) === 0) {
516521
flush_queued_effects([effect]);
@@ -595,7 +600,12 @@ export function schedule_effect(signal) {
595600

596601
if ((flags & BRANCH_EFFECT) !== 0) {
597602
if ((flags & CLEAN) === 0) return;
598-
set_signal_status(effect, MAYBE_DIRTY);
603+
effect.f ^= CLEAN;
604+
}
605+
606+
if ((flags & ROOT_EFFECT) !== 0) {
607+
if ((flags & EFFECT_QUEUED) !== 0) return;
608+
effect.f ^= EFFECT_QUEUED;
599609
}
600610
}
601611

@@ -642,14 +652,7 @@ function process_effects(effect, collected_effects) {
642652
continue;
643653
}
644654
} else if ((flags & EFFECT) !== 0) {
645-
if (is_branch || is_clean) {
646-
if (child !== null) {
647-
current_effect = child;
648-
continue;
649-
}
650-
} else {
651-
effects.push(current_effect);
652-
}
655+
effects.push(current_effect);
653656
}
654657
}
655658

0 commit comments

Comments
 (0)