mirror of https://github.com/sveltejs/svelte
commit
d19a992769
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: ensure element size bindings don't unsubscribe multiple times from the resize observer
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: prevent misidentification of bindings as delegatable event handlers if used outside event attribute
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: preserve current input values when removing defaults
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
chore: improve runtime performance of capturing reactive signals
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: remove document event listeners on unmount
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: preserve component function context for nested components
|
@ -0,0 +1,24 @@
|
||||
import { kairo_avoidable } from './benchmarks/kairo/kairo_avoidable.js';
|
||||
import { kairo_broad } from './benchmarks/kairo/kairo_broad.js';
|
||||
import { kairo_deep } from './benchmarks/kairo/kairo_deep.js';
|
||||
import { kairo_diamond } from './benchmarks/kairo/kairo_diamond.js';
|
||||
import { kairo_mux } from './benchmarks/kairo/kairo_mux.js';
|
||||
import { kairo_repeated } from './benchmarks/kairo/kairo_repeated.js';
|
||||
import { kairo_triangle } from './benchmarks/kairo/kairo_triangle.js';
|
||||
import { kairo_unstable } from './benchmarks/kairo/kairo_unstable.js';
|
||||
import { mol_bench } from './benchmarks/mol_bench.js';
|
||||
|
||||
// This benchmark has been adapted from the js-reactivity-benchmark (https://github.com/milomg/js-reactivity-benchmark)
|
||||
// Not all tests are the same, and many parts have been tweaked to capture different data.
|
||||
|
||||
export const benchmarks = [
|
||||
kairo_avoidable,
|
||||
kairo_broad,
|
||||
kairo_deep,
|
||||
kairo_diamond,
|
||||
kairo_triangle,
|
||||
kairo_mux,
|
||||
kairo_repeated,
|
||||
kairo_unstable,
|
||||
mol_bench
|
||||
];
|
@ -0,0 +1,60 @@
|
||||
import { assert, fastest_test } from '../../utils.js';
|
||||
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
||||
import { busy } from './util.js';
|
||||
|
||||
function setup() {
|
||||
let head = $.source(0);
|
||||
let computed1 = $.derived(() => $.get(head));
|
||||
let computed2 = $.derived(() => ($.get(computed1), 0));
|
||||
let computed3 = $.derived(() => (busy(), $.get(computed2) + 1)); // heavy computation
|
||||
let computed4 = $.derived(() => $.get(computed3) + 2);
|
||||
let computed5 = $.derived(() => $.get(computed4) + 3);
|
||||
|
||||
const destroy = $.effect_root(() => {
|
||||
$.render_effect(() => {
|
||||
$.get(computed5);
|
||||
busy(); // heavy side effect
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
destroy,
|
||||
run() {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, 1);
|
||||
});
|
||||
assert($.get(computed5) === 6);
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, i);
|
||||
});
|
||||
assert($.get(computed5) === 6);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function kairo_avoidable() {
|
||||
// Do 10 loops to warm up JIT
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const { run, destroy } = setup();
|
||||
run();
|
||||
destroy();
|
||||
}
|
||||
|
||||
const { run, destroy } = setup();
|
||||
|
||||
const { timing } = await fastest_test(10, () => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
destroy();
|
||||
|
||||
return {
|
||||
benchmark: 'kairo_avoidable',
|
||||
time: timing.time.toFixed(2),
|
||||
gc_time: timing.gc_time.toFixed(2)
|
||||
};
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
import { assert, fastest_test } from '../../utils.js';
|
||||
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
||||
|
||||
function setup() {
|
||||
let head = $.source(0);
|
||||
let last = head;
|
||||
let counter = 0;
|
||||
|
||||
const destroy = $.effect_root(() => {
|
||||
for (let i = 0; i < 50; i++) {
|
||||
let current = $.derived(() => {
|
||||
return $.get(head) + i;
|
||||
});
|
||||
let current2 = $.derived(() => {
|
||||
return $.get(current) + 1;
|
||||
});
|
||||
$.render_effect(() => {
|
||||
$.get(current2);
|
||||
counter++;
|
||||
});
|
||||
last = current2;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
destroy,
|
||||
run() {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, 1);
|
||||
});
|
||||
counter = 0
|
||||
for (let i = 0; i < 50; i++) {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, i);
|
||||
});
|
||||
assert($.get(last) === i + 50);
|
||||
}
|
||||
assert(counter === 50 * 50);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function kairo_broad() {
|
||||
// Do 10 loops to warm up JIT
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const { run, destroy } = setup();
|
||||
run();
|
||||
destroy();
|
||||
}
|
||||
|
||||
const { run, destroy } = setup();
|
||||
|
||||
const { timing } = await fastest_test(10, () => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
destroy();
|
||||
|
||||
return {
|
||||
benchmark: 'kairo_broad',
|
||||
time: timing.time.toFixed(2),
|
||||
gc_time: timing.gc_time.toFixed(2)
|
||||
};
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
import { assert, fastest_test } from '../../utils.js';
|
||||
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
||||
|
||||
let len = 50;
|
||||
const iter = 50;
|
||||
|
||||
function setup() {
|
||||
let head = $.source(0);
|
||||
let current = head;
|
||||
for (let i = 0; i < len; i++) {
|
||||
let c = current;
|
||||
current = $.derived(() => {
|
||||
return $.get(c) + 1;
|
||||
});
|
||||
}
|
||||
let counter = 0;
|
||||
|
||||
const destroy = $.effect_root(() => {
|
||||
$.render_effect(() => {
|
||||
$.get(current);
|
||||
counter++;
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
destroy,
|
||||
run() {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, 1);
|
||||
});
|
||||
counter = 0
|
||||
for (let i = 0; i < iter; i++) {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, i);
|
||||
});
|
||||
assert($.get(current) === len + i);
|
||||
}
|
||||
assert(counter === iter);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function kairo_deep() {
|
||||
// Do 10 loops to warm up JIT
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const { run, destroy } = setup();
|
||||
run();
|
||||
destroy();
|
||||
}
|
||||
|
||||
const { run, destroy } = setup();
|
||||
|
||||
const { timing } = await fastest_test(10, () => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
destroy();
|
||||
|
||||
return {
|
||||
benchmark: 'kairo_deep',
|
||||
time: timing.time.toFixed(2),
|
||||
gc_time: timing.gc_time.toFixed(2)
|
||||
};
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
import { assert, fastest_test } from '../../utils.js';
|
||||
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
||||
|
||||
let width = 5;
|
||||
|
||||
function setup() {
|
||||
let head = $.source(0);
|
||||
let current = [];
|
||||
for (let i = 0; i < width; i++) {
|
||||
current.push(
|
||||
$.derived(() => {
|
||||
return $.get(head) + 1;
|
||||
})
|
||||
);
|
||||
}
|
||||
let sum = $.derived(() => {
|
||||
return current.map((x) => $.get(x)).reduce((a, b) => a + b, 0);
|
||||
});
|
||||
let counter = 0;
|
||||
|
||||
const destroy = $.effect_root(() => {
|
||||
$.render_effect(() => {
|
||||
$.get(sum);
|
||||
counter++;
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
destroy,
|
||||
run() {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, 1);
|
||||
});
|
||||
assert($.get(sum) === 2 * width);
|
||||
counter = 0;
|
||||
for (let i = 0; i < 500; i++) {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, i);
|
||||
});
|
||||
assert($.get(sum) === (i + 1) * width);
|
||||
}
|
||||
assert(counter === 500);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function kairo_diamond() {
|
||||
// Do 10 loops to warm up JIT
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const { run, destroy } = setup();
|
||||
run();
|
||||
destroy();
|
||||
}
|
||||
|
||||
const { run, destroy } = setup();
|
||||
|
||||
const { timing } = await fastest_test(10, () => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
destroy();
|
||||
|
||||
return {
|
||||
benchmark: 'kairo_diamond',
|
||||
time: timing.time.toFixed(2),
|
||||
gc_time: timing.gc_time.toFixed(2)
|
||||
};
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
import { assert, fastest_test } from '../../utils.js';
|
||||
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
||||
|
||||
function setup() {
|
||||
let heads = new Array(100).fill(null).map((_) => $.source(0));
|
||||
const mux = $.derived(() => {
|
||||
return Object.fromEntries(heads.map((h) => $.get(h)).entries());
|
||||
});
|
||||
const splited = heads
|
||||
.map((_, index) => $.derived(() => $.get(mux)[index]))
|
||||
.map((x) => $.derived(() => $.get(x) + 1));
|
||||
|
||||
const destroy = $.effect_root(() => {
|
||||
splited.forEach((x) => {
|
||||
$.render_effect(() => {
|
||||
$.get(x);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
destroy,
|
||||
run() {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
$.flush_sync(() => {
|
||||
$.set(heads[i], i);
|
||||
});
|
||||
assert($.get(splited[i]) === i + 1);
|
||||
}
|
||||
for (let i = 0; i < 10; i++) {
|
||||
$.flush_sync(() => {
|
||||
$.set(heads[i], i * 2);
|
||||
});
|
||||
assert($.get(splited[i]) === i * 2 + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function kairo_mux() {
|
||||
// Do 10 loops to warm up JIT
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const { run, destroy } = setup();
|
||||
run();
|
||||
destroy();
|
||||
}
|
||||
|
||||
const { run, destroy } = setup();
|
||||
|
||||
const { timing } = await fastest_test(10, () => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
destroy();
|
||||
|
||||
return {
|
||||
benchmark: 'kairo_mux',
|
||||
time: timing.time.toFixed(2),
|
||||
gc_time: timing.gc_time.toFixed(2)
|
||||
};
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
import { assert, fastest_test } from '../../utils.js';
|
||||
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
||||
|
||||
let size = 30;
|
||||
|
||||
function setup() {
|
||||
let head = $.source(0);
|
||||
let current = $.derived(() => {
|
||||
let result = 0;
|
||||
for (let i = 0; i < size; i++) {
|
||||
result += $.get(head);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
let counter = 0;
|
||||
|
||||
const destroy = $.effect_root(() => {
|
||||
$.render_effect(() => {
|
||||
$.get(current);
|
||||
counter++;
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
destroy,
|
||||
run() {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, 1);
|
||||
});
|
||||
assert($.get(current) === size);
|
||||
counter = 0;
|
||||
for (let i = 0; i < 100; i++) {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, i);
|
||||
});
|
||||
assert($.get(current) === i * size);
|
||||
}
|
||||
assert(counter === 100);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function kairo_repeated() {
|
||||
// Do 10 loops to warm up JIT
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const { run, destroy } = setup();
|
||||
run();
|
||||
destroy();
|
||||
}
|
||||
|
||||
const { run, destroy } = setup();
|
||||
|
||||
const { timing } = await fastest_test(10, () => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
destroy();
|
||||
|
||||
return {
|
||||
benchmark: 'kairo_repeated',
|
||||
time: timing.time.toFixed(2),
|
||||
gc_time: timing.gc_time.toFixed(2)
|
||||
};
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
import { assert, fastest_test } from '../../utils.js';
|
||||
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
||||
|
||||
let width = 10;
|
||||
|
||||
function count(number) {
|
||||
return new Array(number)
|
||||
.fill(0)
|
||||
.map((_, i) => i + 1)
|
||||
.reduce((x, y) => x + y, 0);
|
||||
}
|
||||
|
||||
function setup() {
|
||||
let head = $.source(0);
|
||||
let current = head;
|
||||
let list = [];
|
||||
for (let i = 0; i < width; i++) {
|
||||
let c = current;
|
||||
list.push(current);
|
||||
current = $.derived(() => {
|
||||
return $.get(c) + 1;
|
||||
});
|
||||
}
|
||||
let sum = $.derived(() => {
|
||||
return list.map((x) => $.get(x)).reduce((a, b) => a + b, 0);
|
||||
});
|
||||
|
||||
let counter = 0;
|
||||
|
||||
const destroy = $.effect_root(() => {
|
||||
$.render_effect(() => {
|
||||
$.get(sum);
|
||||
counter++;
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
destroy,
|
||||
run() {
|
||||
const constant = count(width);
|
||||
$.flush_sync(() => {
|
||||
$.set(head, 1);
|
||||
});
|
||||
assert($.get(sum) === constant);
|
||||
counter = 0;
|
||||
for (let i = 0; i < 100; i++) {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, i);
|
||||
});
|
||||
assert($.get(sum) === constant - width + i * width);
|
||||
}
|
||||
assert(counter === 100);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function kairo_triangle() {
|
||||
// Do 10 loops to warm up JIT
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const { run, destroy } = setup();
|
||||
run();
|
||||
destroy();
|
||||
}
|
||||
|
||||
const { run, destroy } = setup();
|
||||
|
||||
const { timing } = await fastest_test(10, () => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
destroy();
|
||||
|
||||
return {
|
||||
benchmark: 'kairo_triangle',
|
||||
time: timing.time.toFixed(2),
|
||||
gc_time: timing.gc_time.toFixed(2)
|
||||
};
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
import { assert, fastest_test } from '../../utils.js';
|
||||
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
||||
|
||||
function setup() {
|
||||
let head = $.source(0);
|
||||
const double = $.derived(() => $.get(head) * 2);
|
||||
const inverse = $.derived(() => -$.get(head));
|
||||
let current = $.derived(() => {
|
||||
let result = 0;
|
||||
for (let i = 0; i < 20; i++) {
|
||||
result += $.get(head) % 2 ? $.get(double) : $.get(inverse);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
let counter = 0;
|
||||
|
||||
const destroy = $.effect_root(() => {
|
||||
$.render_effect(() => {
|
||||
$.get(current);
|
||||
counter++;
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
destroy,
|
||||
run() {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, 1);
|
||||
});
|
||||
assert($.get(current) === 40);
|
||||
counter = 0;
|
||||
for (let i = 0; i < 100; i++) {
|
||||
$.flush_sync(() => {
|
||||
$.set(head, i);
|
||||
});
|
||||
}
|
||||
assert(counter === 100);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function kairo_unstable() {
|
||||
// Do 10 loops to warm up JIT
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const { run, destroy } = setup();
|
||||
run();
|
||||
destroy();
|
||||
}
|
||||
|
||||
const { run, destroy } = setup();
|
||||
|
||||
const { timing } = await fastest_test(10, () => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
destroy();
|
||||
|
||||
return {
|
||||
benchmark: 'kairo_unstable',
|
||||
time: timing.time.toFixed(2),
|
||||
gc_time: timing.gc_time.toFixed(2)
|
||||
};
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
|
||||
export function busy() {
|
||||
let a = 0;
|
||||
for (let i = 0; i < 1_00; i++) {
|
||||
a++;
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
import { assert, fastest_test } from '../utils.js';
|
||||
import * as $ from '../../packages/svelte/src/internal/client/index.js';
|
||||
|
||||
/**
|
||||
* @param {number} n
|
||||
*/
|
||||
function fib(n) {
|
||||
if (n < 2) return 1;
|
||||
return fib(n - 1) + fib(n - 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} n
|
||||
*/
|
||||
function hard(n) {
|
||||
return n + fib(16);
|
||||
}
|
||||
|
||||
const numbers = Array.from({ length: 5 }, (_, i) => i);
|
||||
|
||||
function setup() {
|
||||
let res = [];
|
||||
const A = $.source(0);
|
||||
const B = $.source(0);
|
||||
const C = $.derived(() => ($.get(A) % 2) + ($.get(B) % 2));
|
||||
const D = $.derived(() => numbers.map((i) => i + ($.get(A) % 2) - ($.get(B) % 2)));
|
||||
D.equals = function (/** @type {number[]} */ l) {
|
||||
var r = this.v;
|
||||
return r !== null && l.length === r.length && l.every((v, i) => v === r[i]);
|
||||
};
|
||||
const E = $.derived(() => hard($.get(C) + $.get(A) + $.get(D)[0]));
|
||||
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(() => {
|
||||
$.render_effect(() => {
|
||||
res.push(hard($.get(G)));
|
||||
});
|
||||
$.render_effect(() => {
|
||||
res.push($.get(G));
|
||||
});
|
||||
$.render_effect(() => {
|
||||
res.push(hard($.get(F)));
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
destroy,
|
||||
/**
|
||||
* @param {number} i
|
||||
*/
|
||||
run(i) {
|
||||
res.length = 0;
|
||||
$.flush_sync(() => {
|
||||
$.set(B, 1);
|
||||
$.set(A, 1 + i * 2);
|
||||
});
|
||||
$.flush_sync(() => {
|
||||
$.set(A, 2 + i * 2);
|
||||
$.set(B, 2);
|
||||
});
|
||||
assert(res[0] === 3198 && res[1] === 1601 && res[2] === 3195 && res[3] === 1598);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function mol_bench() {
|
||||
// Do 10 loops to warm up JIT
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const { run, destroy } = setup();
|
||||
run(0);
|
||||
destroy();
|
||||
}
|
||||
|
||||
const { run, destroy } = setup();
|
||||
|
||||
const { timing } = await fastest_test(10, () => {
|
||||
for (let i = 0; i < 1e4; i++) {
|
||||
run(i);
|
||||
}
|
||||
});
|
||||
|
||||
destroy();
|
||||
|
||||
return {
|
||||
benchmark: 'mol_bench',
|
||||
time: timing.time.toFixed(2),
|
||||
gc_time: timing.gc_time.toFixed(2)
|
||||
};
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { execSync, fork } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { benchmarks } from '../benchmarks.js';
|
||||
|
||||
// if (execSync('git status --porcelain').toString().trim()) {
|
||||
// console.error('Working directory is not clean');
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
const filename = fileURLToPath(import.meta.url);
|
||||
const runner = path.resolve(filename, '../runner.js');
|
||||
const outdir = path.resolve(filename, '../.results');
|
||||
|
||||
if (fs.existsSync(outdir)) fs.rmSync(outdir, { recursive: true });
|
||||
fs.mkdirSync(outdir);
|
||||
|
||||
const branches = [];
|
||||
|
||||
for (const arg of process.argv.slice(2)) {
|
||||
if (arg.startsWith('--')) continue;
|
||||
if (arg === filename) continue;
|
||||
|
||||
branches.push(arg);
|
||||
}
|
||||
|
||||
if (branches.length === 0) {
|
||||
branches.push(
|
||||
execSync('git symbolic-ref --short -q HEAD || git rev-parse --short HEAD').toString().trim()
|
||||
);
|
||||
}
|
||||
|
||||
if (branches.length === 1) {
|
||||
branches.push('main');
|
||||
}
|
||||
|
||||
process.on('exit', () => {
|
||||
execSync(`git checkout ${branches[0]}`);
|
||||
});
|
||||
|
||||
for (const branch of branches) {
|
||||
console.group(`Benchmarking ${branch}`);
|
||||
|
||||
execSync(`git checkout ${branch}`);
|
||||
|
||||
await new Promise((fulfil, reject) => {
|
||||
const child = fork(runner);
|
||||
|
||||
child.on('message', (results) => {
|
||||
fs.writeFileSync(`${outdir}/${branch}.json`, JSON.stringify(results, null, ' '));
|
||||
fulfil();
|
||||
});
|
||||
|
||||
child.on('error', reject);
|
||||
});
|
||||
|
||||
console.groupEnd();
|
||||
}
|
||||
|
||||
const results = branches.map((branch) => {
|
||||
return JSON.parse(fs.readFileSync(`${outdir}/${branch}.json`, 'utf-8'));
|
||||
});
|
||||
|
||||
for (let i = 0; i < results[0].length; i += 1) {
|
||||
console.group(`${results[0][i].benchmark}`);
|
||||
|
||||
for (const metric of ['time', 'gc_time']) {
|
||||
const times = results.map((result) => +result[i][metric]);
|
||||
let min = Infinity;
|
||||
let min_index = -1;
|
||||
|
||||
for (let b = 0; b < times.length; b += 1) {
|
||||
if (times[b] < min) {
|
||||
min = times[b];
|
||||
min_index = b;
|
||||
}
|
||||
}
|
||||
|
||||
if (min !== 0) {
|
||||
console.group(`${metric}: fastest is ${branches[min_index]}`);
|
||||
times.forEach((time, b) => {
|
||||
console.log(`${branches[b]}: ${time.toFixed(2)}ms (${((time / min) * 100).toFixed(2)}%)`);
|
||||
});
|
||||
console.groupEnd();
|
||||
}
|
||||
}
|
||||
|
||||
console.groupEnd();
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
import { benchmarks } from '../benchmarks.js';
|
||||
|
||||
const results = [];
|
||||
for (const benchmark of benchmarks) {
|
||||
const result = await benchmark();
|
||||
console.error(result.benchmark);
|
||||
results.push(result);
|
||||
}
|
||||
|
||||
process.send(results);
|
@ -0,0 +1,32 @@
|
||||
import * as $ from '../packages/svelte/src/internal/client/index.js';
|
||||
import { benchmarks } from './benchmarks.js';
|
||||
|
||||
let total_time = 0;
|
||||
let total_gc_time = 0;
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('-- Benchmarking Started --');
|
||||
$.push({}, true);
|
||||
try {
|
||||
for (const benchmark of benchmarks) {
|
||||
const results = await benchmark();
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(results);
|
||||
total_time += Number(results.time);
|
||||
total_gc_time += Number(results.gc_time);
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('-- Benchmarking Failed --');
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
$.pop();
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('-- Benchmarking Complete --');
|
||||
// eslint-disable-next-line no-console
|
||||
console.log({
|
||||
total_time: total_time.toFixed(2),
|
||||
total_gc_time: total_gc_time.toFixed(2)
|
||||
});
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "Bundler",
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"verbatimModuleSyntax": true,
|
||||
"isolatedModules": true,
|
||||
"resolveJsonModule": true,
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": true,
|
||||
"checkJs": true
|
||||
},
|
||||
"include": ["./run.js", "./utils.js", "./benchmarks"]
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
import { performance, PerformanceObserver } from 'node:perf_hooks';
|
||||
import v8 from 'v8-natives';
|
||||
|
||||
// Credit to https://github.com/milomg/js-reactivity-benchmark for the logic for timing + GC tracking.
|
||||
|
||||
class GarbageTrack {
|
||||
track_id = 0;
|
||||
observer = new PerformanceObserver((list) => this.perf_entries.push(...list.getEntries()));
|
||||
perf_entries = [];
|
||||
periods = [];
|
||||
|
||||
watch(fn) {
|
||||
this.track_id++;
|
||||
const start = performance.now();
|
||||
const result = fn();
|
||||
const end = performance.now();
|
||||
this.periods.push({ track_id: this.track_id, start, end });
|
||||
|
||||
return { result, track_id: this.track_id };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} track_id
|
||||
*/
|
||||
async gcDuration(track_id) {
|
||||
await promise_delay(10);
|
||||
|
||||
const period = this.periods.find((period) => period.track_id === track_id);
|
||||
if (!period) {
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
||||
return Promise.reject('no period found');
|
||||
}
|
||||
|
||||
const entries = this.perf_entries.filter(
|
||||
(e) => e.startTime >= period.start && e.startTime < period.end
|
||||
);
|
||||
return entries.reduce((t, e) => e.duration + t, 0);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.observer.disconnect();
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.observer.observe({ entryTypes: ['gc'] });
|
||||
}
|
||||
}
|
||||
|
||||
function promise_delay(timeout = 0) {
|
||||
return new Promise((resolve) => setTimeout(resolve, timeout));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ (): void; (): any; }} fn
|
||||
*/
|
||||
function run_timed(fn) {
|
||||
const start = performance.now();
|
||||
const result = fn();
|
||||
const time = performance.now() - start;
|
||||
return { result, time };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {() => void} fn
|
||||
*/
|
||||
async function run_tracked(fn) {
|
||||
v8.collectGarbage();
|
||||
const gc_track = new GarbageTrack();
|
||||
const { result: wrappedResult, track_id } = gc_track.watch(() => run_timed(fn));
|
||||
const gc_time = await gc_track.gcDuration(track_id);
|
||||
const { result, time } = wrappedResult;
|
||||
gc_track.destroy();
|
||||
return { result, timing: { time, gc_time } };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} times
|
||||
* @param {() => void} fn
|
||||
*/
|
||||
export async function fastest_test(times, fn) {
|
||||
const results = [];
|
||||
for (let i = 0; i < times; i++) {
|
||||
const run = await run_tracked(fn);
|
||||
results.push(run);
|
||||
}
|
||||
const fastest = results.reduce((a, b) => (a.timing.time < b.timing.time ? a : b));
|
||||
|
||||
return fastest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} a
|
||||
*/
|
||||
export function assert(a) {
|
||||
if (!a) {
|
||||
throw new Error('Assertion failed');
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
server_props: {
|
||||
name: 'server'
|
||||
},
|
||||
|
||||
props: {
|
||||
name: 'browser'
|
||||
},
|
||||
|
||||
test(assert, target) {
|
||||
const input = target.querySelector('input');
|
||||
assert.equal(input?.value, 'browser');
|
||||
}
|
||||
});
|
@ -0,0 +1 @@
|
||||
<!--[--><input type="text"><!--]-->
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
const { name } = $props();
|
||||
</script>
|
||||
|
||||
<input type="text" value={name} />
|
@ -0,0 +1,7 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test() {
|
||||
// Compiler shouldn't error
|
||||
}
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
function f() {}
|
||||
</script>
|
||||
|
||||
<input onchange={f}>{f}
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
let { children } = $props();
|
||||
</script>
|
||||
|
||||
{@render children()}
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
let { children } = $props();
|
||||
</script>
|
||||
|
||||
{@render children()}
|
@ -0,0 +1,5 @@
|
||||
<script lang="ts">
|
||||
let { count = $bindable() } = $props();
|
||||
</script>
|
||||
|
||||
<button onclick={() => count.value++}>{count.value}</button>
|
@ -0,0 +1,23 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// Tests that nested snippets preserve correct component function context so we don't get false positive warnings
|
||||
export default test({
|
||||
html: `<button>0</button>`,
|
||||
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
test({ assert, target, warnings }) {
|
||||
const button = target.querySelector('button');
|
||||
|
||||
button?.click();
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<button>1</button>`);
|
||||
assert.deepEqual(warnings, []);
|
||||
},
|
||||
|
||||
warnings: []
|
||||
});
|
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
import Component1 from './Component1.svelte';
|
||||
import Component2 from './Component2.svelte';
|
||||
import Component3 from './Component3.svelte';
|
||||
|
||||
let count = $state({ value: 0 });
|
||||
</script>
|
||||
|
||||
<Component1>
|
||||
<Component2>
|
||||
<Component3 bind:count></Component3>
|
||||
</Component2>
|
||||
</Component1>
|
Loading…
Reference in new issue