alternative fix

schedule_effect_perf
Dominic Gannaway 2 months ago
parent 91f4773909
commit ae79dee5d1

@ -10,7 +10,7 @@ function setup() {
let computed4 = $.derived(() => $.get(computed3) + 2);
let computed5 = $.derived(() => $.get(computed4) + 3);
const destroy = $.effect_root(() => {
const destroy = $.user_effect_root(() => {
$.render_effect(() => {
$.get(computed5);
busy(); // heavy side effect
@ -62,7 +62,7 @@ export async function kairo_avoidable_unowned() {
export async function kairo_avoidable_owned() {
let run, destroy;
const destroy_owned = $.effect_root(() => {
const destroy_owned = $.user_effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -6,7 +6,7 @@ function setup() {
let last = head;
let counter = 0;
const destroy = $.effect_root(() => {
const destroy = $.user_effect_root(() => {
for (let i = 0; i < 50; i++) {
let current = $.derived(() => {
return $.get(head) + i;
@ -68,7 +68,7 @@ export async function kairo_broad_unowned() {
export async function kairo_broad_owned() {
let run, destroy;
const destroy_owned = $.effect_root(() => {
const destroy_owned = $.user_effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -15,7 +15,7 @@ function setup() {
}
let counter = 0;
const destroy = $.effect_root(() => {
const destroy = $.user_effect_root(() => {
$.render_effect(() => {
$.get(current);
counter++;
@ -68,7 +68,7 @@ export async function kairo_deep_unowned() {
export async function kairo_deep_owned() {
let run, destroy;
const destroy_owned = $.effect_root(() => {
const destroy_owned = $.user_effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -18,7 +18,7 @@ function setup() {
});
let counter = 0;
const destroy = $.effect_root(() => {
const destroy = $.user_effect_root(() => {
$.render_effect(() => {
$.get(sum);
counter++;
@ -72,7 +72,7 @@ export async function kairo_diamond_unowned() {
export async function kairo_diamond_owned() {
let run, destroy;
const destroy_owned = $.effect_root(() => {
const destroy_owned = $.user_effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -10,7 +10,7 @@ function setup() {
.map((_, index) => $.derived(() => $.get(mux)[index]))
.map((x) => $.derived(() => $.get(x) + 1));
const destroy = $.effect_root(() => {
const destroy = $.user_effect_root(() => {
splited.forEach((x) => {
$.render_effect(() => {
$.get(x);
@ -65,7 +65,7 @@ export async function kairo_mux_unowned() {
export async function kairo_mux_owned() {
let run, destroy;
const destroy_owned = $.effect_root(() => {
const destroy_owned = $.user_effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -15,7 +15,7 @@ function setup() {
let counter = 0;
const destroy = $.effect_root(() => {
const destroy = $.user_effect_root(() => {
$.render_effect(() => {
$.get(current);
counter++;
@ -69,7 +69,7 @@ export async function kairo_repeated_unowned() {
export async function kairo_repeated_owned() {
let run, destroy;
const destroy_owned = $.effect_root(() => {
const destroy_owned = $.user_effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -27,7 +27,7 @@ function setup() {
let counter = 0;
const destroy = $.effect_root(() => {
const destroy = $.user_effect_root(() => {
$.render_effect(() => {
$.get(sum);
counter++;
@ -82,7 +82,7 @@ export async function kairo_triangle_unowned() {
export async function kairo_triangle_owned() {
let run, destroy;
const destroy_owned = $.effect_root(() => {
const destroy_owned = $.user_effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -15,7 +15,7 @@ function setup() {
let counter = 0;
const destroy = $.effect_root(() => {
const destroy = $.user_effect_root(() => {
$.render_effect(() => {
$.get(current);
counter++;
@ -68,7 +68,7 @@ export async function kairo_unstable_unowned() {
export async function kairo_unstable_owned() {
let run, destroy;
const destroy_owned = $.effect_root(() => {
const destroy_owned = $.user_effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -32,7 +32,7 @@ function setup() {
const F = $.derived(() => hard($.get(D)[0] && $.get(B)));
const G = $.derived(() => $.get(C) + ($.get(C) || $.get(E) % 2) + $.get(D)[0] + $.get(F));
const destroy = $.effect_root(() => {
const destroy = $.user_effect_root(() => {
$.render_effect(() => {
res.push(hard($.get(G)));
});
@ -67,7 +67,7 @@ function setup() {
export async function mol_bench_owned() {
let run, destroy;
const destroy_owned = $.effect_root(() => {
const destroy_owned = $.user_effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -26,7 +26,7 @@ export function CallExpression(node, context) {
case '$effect.root':
return b.call(
'$.effect_root',
'$.user_effect_root',
.../** @type {Expression[]} */ (node.arguments.map((arg) => context.visit(arg)))
);

@ -96,7 +96,7 @@ export {
export { derived, derived_safe_equal } from './reactivity/deriveds.js';
export {
effect_tracking,
effect_root,
user_effect_root,
legacy_pre_effect,
legacy_pre_effect_reset,
render_effect,

@ -232,7 +232,6 @@ export function inspect_effect(fn) {
}
/**
* Internal representation of `$effect.root(...)`
* @param {() => void | (() => void)} fn
* @returns {() => void}
*/
@ -243,6 +242,17 @@ export function effect_root(fn) {
};
}
/**
* Internal representation of `$effect.root(...)`
* @param {() => void | (() => void)} fn
* @returns {() => void}
*/
export function user_effect_root(fn) {
return effect_root(() => {
branch(fn);
});
}
/**
* @param {() => void | (() => void)} fn
* @returns {Effect}

@ -592,9 +592,7 @@ export function schedule_effect(signal) {
}
}
if (!queued_root_effects.includes(effect)) {
queued_root_effects.push(effect);
}
queued_root_effects.push(effect);
}
/**

@ -11,7 +11,7 @@ import {
} from 'svelte/store';
import { source, set } from '../../src/internal/client/reactivity/sources';
import * as $ from '../../src/internal/client/runtime';
import { effect_root, render_effect } from 'svelte/internal/client';
import { user_effect_root, render_effect } from 'svelte/internal/client';
describe('writable', () => {
it('creates a writable store', () => {
@ -645,7 +645,7 @@ describe('fromStore', () => {
const log: number[] = [];
const teardown = effect_root(() => {
const teardown = user_effect_root(() => {
render_effect(() => {
log.push(count.current);
});

Loading…
Cancel
Save