Skip to content

Commit 7865ddc

Browse files
committed
Merge branch 'main' into optional-render-options
2 parents 00f5f03 + e9e7d8b commit 7865ddc

30 files changed

+951
-133
lines changed

.changeset/gorgeous-boxes-design.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: ensure state update expressions are serialised correctly

.changeset/pre.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@
529529
"strong-lemons-provide",
530530
"strong-pans-doubt",
531531
"stupid-parents-crash",
532+
"sweet-bottles-check",
532533
"sweet-mangos-beg",
533534
"sweet-pens-sniff",
534535
"swift-donkeys-perform",

.changeset/sweet-bottles-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+
chore: improve runtime performance of capturing reactive signals

.changeset/twenty-gifts-develop.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: remove document event listeners on unmount

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ coverage
2222
.DS_Store
2323

2424
tmp
25+
26+
benchmarking/compare/.results

benchmarking/benchmarks.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import {
2+
kairo_avoidable_owned,
3+
kairo_avoidable_unowned
4+
} from './benchmarks/kairo/kairo_avoidable.js';
5+
import { kairo_broad_owned, kairo_broad_unowned } from './benchmarks/kairo/kairo_broad.js';
6+
import { kairo_deep_owned, kairo_deep_unowned } from './benchmarks/kairo/kairo_deep.js';
7+
import { kairo_diamond_owned, kairo_diamond_unowned } from './benchmarks/kairo/kairo_diamond.js';
8+
import { kairo_mux_unowned, kairo_mux_owned } from './benchmarks/kairo/kairo_mux.js';
9+
import { kairo_repeated_unowned, kairo_repeated_owned } from './benchmarks/kairo/kairo_repeated.js';
10+
import { kairo_triangle_owned, kairo_triangle_unowned } from './benchmarks/kairo/kairo_triangle.js';
11+
import { kairo_unstable_owned, kairo_unstable_unowned } from './benchmarks/kairo/kairo_unstable.js';
12+
import { mol_bench_owned, mol_bench_unowned } from './benchmarks/mol_bench.js';
13+
import {
14+
sbench_create_0to1,
15+
sbench_create_1000to1,
16+
sbench_create_1to1,
17+
sbench_create_1to1000,
18+
sbench_create_1to2,
19+
sbench_create_1to4,
20+
sbench_create_1to8,
21+
sbench_create_2to1,
22+
sbench_create_4to1,
23+
sbench_create_signals
24+
} from './benchmarks/sbench.js';
25+
26+
// This benchmark has been adapted from the js-reactivity-benchmark (https://github.com/milomg/js-reactivity-benchmark)
27+
// Not all tests are the same, and many parts have been tweaked to capture different data.
28+
29+
export const benchmarks = [
30+
sbench_create_signals,
31+
sbench_create_0to1,
32+
sbench_create_1to1,
33+
sbench_create_2to1,
34+
sbench_create_4to1,
35+
sbench_create_1000to1,
36+
sbench_create_1to2,
37+
sbench_create_1to4,
38+
sbench_create_1to8,
39+
sbench_create_1to1000,
40+
kairo_avoidable_owned,
41+
kairo_avoidable_unowned,
42+
kairo_broad_owned,
43+
kairo_broad_unowned,
44+
kairo_deep_owned,
45+
kairo_deep_unowned,
46+
kairo_diamond_owned,
47+
kairo_diamond_unowned,
48+
kairo_triangle_owned,
49+
kairo_triangle_unowned,
50+
kairo_mux_owned,
51+
kairo_mux_unowned,
52+
kairo_repeated_owned,
53+
kairo_repeated_unowned,
54+
kairo_unstable_owned,
55+
kairo_unstable_unowned,
56+
mol_bench_owned,
57+
mol_bench_unowned
58+
];

benchmarking/benchmarks/kairo/kairo_avoidable.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function setup() {
3434
};
3535
}
3636

37-
export async function kairo_avoidable() {
37+
export async function kairo_avoidable_unowned() {
3838
// Do 10 loops to warm up JIT
3939
for (let i = 0; i < 10; i++) {
4040
const { run, destroy } = setup();
@@ -53,7 +53,38 @@ export async function kairo_avoidable() {
5353
destroy();
5454

5555
return {
56-
benchmark: 'kairo_avoidable',
56+
benchmark: 'kairo_avoidable_unowned',
57+
time: timing.time.toFixed(2),
58+
gc_time: timing.gc_time.toFixed(2)
59+
};
60+
}
61+
62+
export async function kairo_avoidable_owned() {
63+
let run, destroy;
64+
65+
const destroy_owned = $.effect_root(() => {
66+
// Do 10 loops to warm up JIT
67+
for (let i = 0; i < 10; i++) {
68+
const { run, destroy } = setup();
69+
run();
70+
destroy();
71+
}
72+
73+
({ run, destroy } = setup());
74+
});
75+
76+
const { timing } = await fastest_test(10, () => {
77+
for (let i = 0; i < 100; i++) {
78+
run();
79+
}
80+
});
81+
82+
// @ts-ignore
83+
destroy();
84+
destroy_owned();
85+
86+
return {
87+
benchmark: 'kairo_avoidable_owned',
5788
time: timing.time.toFixed(2),
5889
gc_time: timing.gc_time.toFixed(2)
5990
};

benchmarking/benchmarks/kairo/kairo_broad.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function setup() {
2828
$.flush_sync(() => {
2929
$.set(head, 1);
3030
});
31-
counter = 0
31+
counter = 0;
3232
for (let i = 0; i < 50; i++) {
3333
$.flush_sync(() => {
3434
$.set(head, i);
@@ -40,7 +40,7 @@ function setup() {
4040
};
4141
}
4242

43-
export async function kairo_broad() {
43+
export async function kairo_broad_unowned() {
4444
// Do 10 loops to warm up JIT
4545
for (let i = 0; i < 10; i++) {
4646
const { run, destroy } = setup();
@@ -59,7 +59,38 @@ export async function kairo_broad() {
5959
destroy();
6060

6161
return {
62-
benchmark: 'kairo_broad',
62+
benchmark: 'kairo_broad_unowned',
63+
time: timing.time.toFixed(2),
64+
gc_time: timing.gc_time.toFixed(2)
65+
};
66+
}
67+
68+
export async function kairo_broad_owned() {
69+
let run, destroy;
70+
71+
const destroy_owned = $.effect_root(() => {
72+
// Do 10 loops to warm up JIT
73+
for (let i = 0; i < 10; i++) {
74+
const { run, destroy } = setup();
75+
run();
76+
destroy();
77+
}
78+
79+
({ run, destroy } = setup());
80+
});
81+
82+
const { timing } = await fastest_test(10, () => {
83+
for (let i = 0; i < 100; i++) {
84+
run();
85+
}
86+
});
87+
88+
// @ts-ignore
89+
destroy();
90+
destroy_owned();
91+
92+
return {
93+
benchmark: 'kairo_broad_owned',
6394
time: timing.time.toFixed(2),
6495
gc_time: timing.gc_time.toFixed(2)
6596
};

benchmarking/benchmarks/kairo/kairo_deep.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ function setup() {
88
let head = $.source(0);
99
let current = head;
1010
for (let i = 0; i < len; i++) {
11-
let c = current;
12-
current = $.derived(() => {
13-
return $.get(c) + 1;
14-
});
15-
}
16-
let counter = 0;
11+
let c = current;
12+
current = $.derived(() => {
13+
return $.get(c) + 1;
14+
});
15+
}
16+
let counter = 0;
1717

1818
const destroy = $.effect_root(() => {
1919
$.render_effect(() => {
@@ -28,7 +28,7 @@ function setup() {
2828
$.flush_sync(() => {
2929
$.set(head, 1);
3030
});
31-
counter = 0
31+
counter = 0;
3232
for (let i = 0; i < iter; i++) {
3333
$.flush_sync(() => {
3434
$.set(head, i);
@@ -40,7 +40,7 @@ function setup() {
4040
};
4141
}
4242

43-
export async function kairo_deep() {
43+
export async function kairo_deep_unowned() {
4444
// Do 10 loops to warm up JIT
4545
for (let i = 0; i < 10; i++) {
4646
const { run, destroy } = setup();
@@ -59,7 +59,38 @@ export async function kairo_deep() {
5959
destroy();
6060

6161
return {
62-
benchmark: 'kairo_deep',
62+
benchmark: 'kairo_deep_unowned',
63+
time: timing.time.toFixed(2),
64+
gc_time: timing.gc_time.toFixed(2)
65+
};
66+
}
67+
68+
export async function kairo_deep_owned() {
69+
let run, destroy;
70+
71+
const destroy_owned = $.effect_root(() => {
72+
// Do 10 loops to warm up JIT
73+
for (let i = 0; i < 10; i++) {
74+
const { run, destroy } = setup();
75+
run();
76+
destroy();
77+
}
78+
79+
({ run, destroy } = setup());
80+
});
81+
82+
const { timing } = await fastest_test(10, () => {
83+
for (let i = 0; i < 100; i++) {
84+
run();
85+
}
86+
});
87+
88+
// @ts-ignore
89+
destroy();
90+
destroy_owned();
91+
92+
return {
93+
benchmark: 'kairo_deep_owned',
6394
time: timing.time.toFixed(2),
6495
gc_time: timing.gc_time.toFixed(2)
6596
};

benchmarking/benchmarks/kairo/kairo_diamond.js

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ let width = 5;
55

66
function setup() {
77
let head = $.source(0);
8-
let current = [];
9-
for (let i = 0; i < width; i++) {
10-
current.push(
11-
$.derived(() => {
12-
return $.get(head) + 1;
13-
})
14-
);
15-
}
16-
let sum = $.derived(() => {
17-
return current.map((x) => $.get(x)).reduce((a, b) => a + b, 0);
18-
});
8+
let current = [];
9+
for (let i = 0; i < width; i++) {
10+
current.push(
11+
$.derived(() => {
12+
return $.get(head) + 1;
13+
})
14+
);
15+
}
16+
let sum = $.derived(() => {
17+
return current.map((x) => $.get(x)).reduce((a, b) => a + b, 0);
18+
});
1919
let counter = 0;
2020

2121
const destroy = $.effect_root(() => {
@@ -44,7 +44,7 @@ function setup() {
4444
};
4545
}
4646

47-
export async function kairo_diamond() {
47+
export async function kairo_diamond_unowned() {
4848
// Do 10 loops to warm up JIT
4949
for (let i = 0; i < 10; i++) {
5050
const { run, destroy } = setup();
@@ -63,7 +63,38 @@ export async function kairo_diamond() {
6363
destroy();
6464

6565
return {
66-
benchmark: 'kairo_diamond',
66+
benchmark: 'kairo_diamond_unowned',
67+
time: timing.time.toFixed(2),
68+
gc_time: timing.gc_time.toFixed(2)
69+
};
70+
}
71+
72+
export async function kairo_diamond_owned() {
73+
let run, destroy;
74+
75+
const destroy_owned = $.effect_root(() => {
76+
// Do 10 loops to warm up JIT
77+
for (let i = 0; i < 10; i++) {
78+
const { run, destroy } = setup();
79+
run();
80+
destroy();
81+
}
82+
83+
({ run, destroy } = setup());
84+
});
85+
86+
const { timing } = await fastest_test(10, () => {
87+
for (let i = 0; i < 100; i++) {
88+
run();
89+
}
90+
});
91+
92+
// @ts-ignore
93+
destroy();
94+
destroy_owned();
95+
96+
return {
97+
benchmark: 'kairo_diamond_owned',
6798
time: timing.time.toFixed(2),
6899
gc_time: timing.gc_time.toFixed(2)
69100
};

0 commit comments

Comments
 (0)