incremental-batches
Rich Harris 3 weeks ago
parent fa580d895a
commit 5d5ce8b277

@ -41,7 +41,6 @@ import { tag } from '../../dev/tracing.js';
import { createSubscriber } from '../../../../reactivity/create-subscriber.js';
import { create_text } from '../operations.js';
import { defer_effect } from '../../reactivity/utils.js';
import { set_signal_status } from '../../reactivity/status.js';
/**
* @typedef {{

@ -36,7 +36,6 @@ import { flush_eager_effects, old_values, set_eager_effects, source, update } fr
import { eager_effect, unlink_effect } from './effects.js';
import { defer_effect } from './utils.js';
import { UNINITIALIZED } from '../../../constants.js';
import { set_signal_status } from './status.js';
import { legacy_is_updating_store } from './store.js';
import { invariant } from '../../shared/dev.js';
import { log_effect_tree, root } from '../dev/debug.js';
@ -222,12 +221,10 @@ export class Batch {
this.#skipped_branches.delete(effect);
for (var e of tracked.d) {
set_signal_status(e, DIRTY);
this.schedule(e);
}
for (e of tracked.m) {
set_signal_status(e, MAYBE_DIRTY);
this.schedule(e);
}
}
@ -244,12 +241,10 @@ export class Batch {
if (!this.#is_deferred()) {
for (const e of this.#dirty_effects) {
this.#maybe_dirty_effects.delete(e);
set_signal_status(e, DIRTY);
this.schedule(e);
}
for (const e of this.#maybe_dirty_effects) {
set_signal_status(e, MAYBE_DIRTY);
this.schedule(e);
}
}
@ -928,7 +923,6 @@ function mark_effects(value, sources, marked, checked) {
(flags & DIRTY) === 0 &&
depends_on(reaction, sources, checked)
) {
set_signal_status(reaction, DIRTY);
schedule_effect(/** @type {Effect} */ (reaction));
}
}
@ -951,7 +945,6 @@ function mark_eager_effects(value, effects) {
if ((flags & DERIVED) !== 0) {
mark_eager_effects(/** @type {Derived} */ (reaction), effects);
} else if ((flags & EAGER_EFFECT) !== 0) {
set_signal_status(reaction, DIRTY);
effects.add(/** @type {Effect} */ (reaction));
}
}
@ -1070,8 +1063,6 @@ function reset_branch(effect, tracked) {
tracked.m.push(effect);
}
set_signal_status(effect, CLEAN);
var e = effect.first;
while (e !== null) {
reset_branch(e, tracked);
@ -1084,8 +1075,6 @@ function reset_branch(effect, tracked) {
* @param {Effect} effect
*/
function reset_all(effect) {
set_signal_status(effect, CLEAN);
var e = effect.first;
while (e !== null) {
reset_all(e);

@ -44,7 +44,6 @@ import { UNINITIALIZED } from '../../../constants.js';
import { batch_values, current_batch } from './batch.js';
import { increment_pending, unset_context } from './async.js';
import { deferred, includes, noop } from '../../shared/utils.js';
import { set_signal_status, update_derived_status } from './status.js';
/**
* This allows us to track 'reactivity loss' that occurs when signals
@ -404,7 +403,6 @@ export function update_derived(derived) {
// deriveds without dependencies should never be recomputed
if (derived.deps === null) {
set_signal_status(derived, CLEAN);
return;
}
}
@ -424,8 +422,6 @@ export function update_derived(derived) {
if (effect_tracking() || current_batch?.is_fork) {
batch_values.set(derived, value);
}
} else {
update_derived_status(derived);
}
}

@ -45,7 +45,6 @@ import { component_context, dev_current_component_function, dev_stack } from '..
import { Batch, collected_effects } from './batch.js';
import { flatten, increment_pending } from './async.js';
import { without_reactive_context } from '../dom/elements/bindings/shared.js';
import { set_signal_status } from './status.js';
/**
* @param {'$effect' | '$effect.pre' | '$inspect'} rune
@ -191,7 +190,6 @@ export function effect_tracking() {
*/
export function teardown(fn) {
const effect = create_effect(RENDER_EFFECT, null);
set_signal_status(effect, CLEAN);
effect.teardown = fn;
return effect;
}
@ -344,12 +342,6 @@ export function legacy_pre_effect_reset() {
var effect = token.effect;
// If the effect is CLEAN, then make it MAYBE_DIRTY. This ensures we traverse through
// the effects dependencies and correctly ensure each dependency is up-to-date.
if ((effect.f & CLEAN) !== 0 && effect.deps !== null) {
set_signal_status(effect, MAYBE_DIRTY);
}
if (is_dirty(effect)) {
update_effect(effect);
}
@ -522,7 +514,7 @@ export function destroy_effect(effect, remove_dom = true) {
removed = true;
}
set_signal_status(effect, DESTROYING);
effect.f |= DESTROYING;
destroy_effect_children(effect, remove_dom && !removed);
remove_reactions(effect, 0);
@ -689,7 +681,6 @@ function resume_children(effect, local) {
// here because we don't want to eagerly recompute a derived like
// `{#if foo}{foo.bar()}{/if}` if `foo` is now `undefined
if ((effect.f & CLEAN) === 0) {
set_signal_status(effect, DIRTY);
Batch.ensure().schedule(effect); // Assumption: This happens during the commit phase of the batch, causing another flush, but it's safe
}

@ -44,7 +44,6 @@ import {
} from './batch.js';
import { proxy } from '../proxy.js';
import { execute_derived } from './deriveds.js';
import { set_signal_status, update_derived_status } from './status.js';
/** @type {Set<any>} */
export let eager_effects = new Set();
@ -231,12 +230,6 @@ export function internal_set(source, value, updated_during_traversal = null) {
if ((source.f & DIRTY) !== 0) {
execute_derived(derived);
}
// During time traveling we don't want to reset the status so that
// traversal of the graph in the other batches still happens
if (batch_values === null) {
update_derived_status(derived);
}
}
source.wv = source.cv = increment_write_version();
@ -274,12 +267,6 @@ export function flush_eager_effects() {
eager_effects_deferred = false;
for (const effect of eager_effects) {
// Mark clean inspect-effects as maybe dirty and then check their dirtiness
// instead of just updating the effects - this way we avoid overfiring.
if ((effect.f & CLEAN) !== 0) {
set_signal_status(effect, MAYBE_DIRTY);
}
if (is_dirty(effect)) {
update_effect(effect);
}
@ -352,13 +339,6 @@ function mark_reactions(signal, status, updated_during_traversal) {
continue;
}
var not_dirty = (flags & DIRTY) === 0;
// don't set a DIRTY reaction to MAYBE_DIRTY
if (not_dirty) {
set_signal_status(reaction, status);
}
if ((flags & DERIVED) !== 0) {
var derived = /** @type {Derived} */ (reaction);

@ -1,25 +0,0 @@
/** @import { Derived, Signal } from '#client' */
import { CLEAN, CONNECTED, DIRTY, MAYBE_DIRTY } from '#client/constants';
const STATUS_MASK = ~(DIRTY | MAYBE_DIRTY | CLEAN);
/**
* @param {Signal} signal
* @param {number} status
*/
export function set_signal_status(signal, status) {
// signal.f = (signal.f & STATUS_MASK) | status;
}
/**
* Set a derived's status to CLEAN or MAYBE_DIRTY based on its connection state.
* @param {Derived} derived
*/
export function update_derived_status(derived) {
// Only mark as MAYBE_DIRTY if disconnected and has dependencies.
if ((derived.f & CONNECTED) !== 0 || derived.deps === null) {
set_signal_status(derived, CLEAN);
} else {
set_signal_status(derived, MAYBE_DIRTY);
}
}

@ -1,6 +1,5 @@
/** @import { Derived, Effect, Value } from '#client' */
import { CLEAN, DERIVED, DIRTY, MAYBE_DIRTY, WAS_MARKED } from '#client/constants';
import { set_signal_status } from './status.js';
import { DERIVED, WAS_MARKED } from '#client/constants';
/**
* @param {Value[] | null} deps
@ -27,15 +26,7 @@ function clear_marked(deps) {
export function defer_effect(effect, dirty_effects, maybe_dirty_effects) {
dirty_effects.add(effect);
// if ((effect.f & DIRTY) !== 0) {
// } else if ((effect.f & MAYBE_DIRTY) !== 0) {
// maybe_dirty_effects.add(effect);
// }
// Since we're not executing these effects now, we need to clear any WAS_MARKED flags
// so that other batches can correctly reach these effects during their own traversal
clear_marked(effect.deps);
// mark as clean so they get scheduled if they depend on pending async state
set_signal_status(effect, CLEAN);
}

@ -57,7 +57,6 @@ import { handle_error } from './error-handling.js';
import { UNINITIALIZED } from '../../constants.js';
import { captured_signals } from './legacy.js';
import { without_reactive_context } from './dom/elements/bindings/shared.js';
import { set_signal_status, update_derived_status } from './reactivity/status.js';
import * as w from './warnings.js';
let is_updating_effect = false;
@ -182,15 +181,6 @@ export function is_dirty(reaction) {
return true;
}
}
if (
(flags & CONNECTED) !== 0 &&
// During time traveling we don't want to reset the status so that
// traversal of the graph in the other batches still happens
batch_values === null
) {
set_signal_status(reaction, CLEAN);
}
}
reaction.cv = write_version;
@ -217,11 +207,6 @@ function schedule_possible_effect_self_invalidation(signal, effect, root = true)
if ((reaction.f & DERIVED) !== 0) {
schedule_possible_effect_self_invalidation(/** @type {Derived} */ (reaction), effect, false);
} else if (effect === reaction) {
if (root) {
set_signal_status(reaction, DIRTY);
} else if ((reaction.f & CLEAN) !== 0) {
set_signal_status(reaction, MAYBE_DIRTY);
}
schedule_effect(/** @type {Effect} */ (reaction));
}
}
@ -404,8 +389,6 @@ function remove_reaction(signal, dependency) {
derived.f &= ~WAS_MARKED;
}
update_derived_status(derived);
// freeze any effects inside this derived
freeze_derived_effects(derived);
@ -439,8 +422,6 @@ export function update_effect(effect) {
return;
}
set_signal_status(effect, CLEAN);
var previous_effect = active_effect;
var was_updating_effect = is_updating_effect;

@ -1,5 +1,5 @@
/** @import { ComponentConstructorOptions, ComponentType, SvelteComponent, Component } from 'svelte' */
import { DIRTY, LEGACY_PROPS, MAYBE_DIRTY } from '../internal/client/constants.js';
import { DIRTY, LEGACY_PROPS } from '../internal/client/constants.js';
import { user_pre_effect } from '../internal/client/reactivity/effects.js';
import { mutable_source, set } from '../internal/client/reactivity/sources.js';
import { hydrate, mount, unmount } from '../internal/client/render.js';
@ -12,7 +12,6 @@ import { DEV } from 'esm-env';
import { FILENAME } from '../constants.js';
import { component_context, dev_current_component_function } from '../internal/client/context.js';
import { async_mode_flag } from '../internal/flags/index.js';
import { set_signal_status } from '../internal/client/reactivity/status.js';
/**
* Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component.
@ -199,7 +198,6 @@ export function run(fn) {
filename = dev_current_component_function?.[FILENAME] ?? filename;
}
w.legacy_recursive_reactive_block(filename);
set_signal_status(effect, MAYBE_DIRTY);
}
});
}

Loading…
Cancel
Save