prune effects where possible

pull/16625/head
Rich Harris 3 weeks ago
parent 8d710765c2
commit d4696fd020

@ -134,19 +134,28 @@ function create_effect(type, fn, sync, push = true) {
} }
if (push) { if (push) {
// if an effect has no dependencies, no DOM and no teardown function, var e = /** @type {Effect | null} */ (effect);
// don't bother adding it to the effect tree
var inert = // if an effect has already ran and doesn't need to be kept in the tree
sync && // (because it won't re-run, has no DOM, and has no teardown etc)
effect.deps === null && // then we skip it and go to its child (if any)
effect.first === null && while (
effect.nodes_start === null && e !== null &&
effect.teardown === null && e.deps === null &&
(effect.f & EFFECT_PRESERVED) === 0; e.teardown === null &&
e.nodes_start === null &&
if (!inert) { (e.f & EFFECT_RAN) !== 0 &&
(e.f & ROOT_EFFECT) === 0 &&
(e.f & BRANCH_EFFECT) === 0 &&
(e.f & EFFECT_PRESERVED) === 0
) {
if (e.first !== e.last) break;
e = e.first;
}
if (e !== null) {
if (parent !== null) { if (parent !== null) {
push_effect(effect, parent); push_effect(e, parent);
} }
// if we're in a derived, add the effect there too // if we're in a derived, add the effect there too
@ -156,7 +165,7 @@ function create_effect(type, fn, sync, push = true) {
(type & ROOT_EFFECT) === 0 (type & ROOT_EFFECT) === 0
) { ) {
var derived = /** @type {Derived} */ (active_reaction); var derived = /** @type {Derived} */ (active_reaction);
(derived.effects ??= []).push(effect); (derived.effects ??= []).push(e);
} }
} }
} }

Loading…
Cancel
Save