Skip to content

Commit c6a8379

Browse files
mlrawlingsDylanPiercey
authored andcommitted
refactor: less queueing for loop closures
1 parent fa8f1c1 commit c6a8379

File tree

4 files changed

+65
-40
lines changed

4 files changed

+65
-40
lines changed

.sizes.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
{
88
"name": "*",
99
"total": {
10-
"min": 17441,
11-
"brotli": 6584
10+
"min": 17482,
11+
"brotli": 6602
1212
}
1313
},
1414
{
1515
"name": "counter",
1616
"user": {
1717
"min": 189,
18-
"brotli": 143
18+
"brotli": 144
1919
},
2020
"runtime": {
2121
"min": 4023,
22-
"brotli": 1759
22+
"brotli": 1769
2323
},
2424
"total": {
2525
"min": 4212,
26-
"brotli": 1902
26+
"brotli": 1913
2727
}
2828
},
2929
{
@@ -34,11 +34,11 @@
3434
},
3535
"runtime": {
3636
"min": 3276,
37-
"brotli": 1498
37+
"brotli": 1491
3838
},
3939
"total": {
4040
"min": 3387,
41-
"brotli": 1598
41+
"brotli": 1591
4242
}
4343
},
4444
{
@@ -48,12 +48,12 @@
4848
"brotli": 485
4949
},
5050
"runtime": {
51-
"min": 6906,
52-
"brotli": 2947
51+
"min": 6947,
52+
"brotli": 2960
5353
},
5454
"total": {
55-
"min": 7908,
56-
"brotli": 3432
55+
"min": 7949,
56+
"brotli": 3445
5757
}
5858
},
5959
{
@@ -64,11 +64,11 @@
6464
},
6565
"runtime": {
6666
"min": 3443,
67-
"brotli": 1548
67+
"brotli": 1551
6868
},
6969
"total": {
7070
"min": 3588,
71-
"brotli": 1668
71+
"brotli": 1671
7272
}
7373
}
7474
]

.sizes/counter.csr/entry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// size: 189 (min) 143 (brotli)
1+
// size: 189 (min) 144 (brotli)
22
const _clickCount_effect = effect("a0", (_scope, { 2: clickCount }) =>
33
on(_scope[0], "click", function () {
44
_clickCount(_scope, clickCount + 1);

.sizes/dom.js

+33-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// size: 17441 (min) 6584 (brotli)
1+
// size: 17482 (min) 6602 (brotli)
22
var empty = [],
33
rest = Symbol();
44
function attrTag(attrs2) {
@@ -97,10 +97,10 @@ var registeredValues = {},
9797
Render = class {
9898
l = [];
9999
m = {};
100-
z = { _: registeredValues };
100+
A = { _: registeredValues };
101101
constructor(renders, runtimeId, renderId) {
102-
(this.A = renders),
103-
(this.B = runtimeId),
102+
(this.B = renders),
103+
(this.C = runtimeId),
104104
(this.n = renderId),
105105
(this.o = renders[renderId]),
106106
this.p();
@@ -110,7 +110,7 @@ var registeredValues = {},
110110
}
111111
p() {
112112
let data2 = this.o,
113-
serializeContext = this.z,
113+
serializeContext = this.A,
114114
scopeLookup = this.m,
115115
visits = data2.v,
116116
branchIds = new Set(),
@@ -200,7 +200,7 @@ var registeredValues = {},
200200
{ $global: $global } = scopeLookup;
201201
$global ||
202202
((scopeLookup.$global = $global = scopes.$ || {}),
203-
($global.runtimeId = this.B),
203+
($global.runtimeId = this.C),
204204
($global.renderId = this.n));
205205
for (let scopeId in scopes)
206206
if ("$" !== scopeId) {
@@ -225,7 +225,7 @@ var registeredValues = {},
225225
}
226226
} else
227227
i === len || "string" != typeof resumes[i]
228-
? delete this.A[this.n]
228+
? delete this.B[this.n]
229229
: registeredValues[resumes[i++]](
230230
scopeLookup[resumeData],
231231
scopeLookup[resumeData],
@@ -781,7 +781,7 @@ function destroyBranch(branch) {
781781
branch.q?.j?.delete(branch), destroyNestedBranches(branch);
782782
}
783783
function destroyNestedBranches(branch) {
784-
(branch.C = 1),
784+
(branch.s = 1),
785785
branch.j?.forEach(destroyNestedBranches),
786786
branch.D?.forEach((scope) => {
787787
for (let id in scope.g) scope.g[id]?.abort();
@@ -800,10 +800,10 @@ var pendingRenders = [],
800800
function queueRender(scope, signal, signalKey, value2, scopeKey = scope.d) {
801801
let key = 1024 * scopeKey + signalKey,
802802
existingRender = -1 !== signalKey && pendingRendersLookup.get(key);
803-
if (existingRender) existingRender.s = value2;
803+
if (existingRender) existingRender.t = value2;
804804
else {
805805
let i = pendingRenders.length,
806-
render = { t: scope, E: signal, s: value2, u: key };
806+
render = { u: scope, E: signal, t: value2, x: key };
807807
for (
808808
pendingRendersLookup.set(key, render), pendingRenders.push(render);
809809
i;
@@ -879,15 +879,15 @@ function runRenders() {
879879
}
880880
pendingRenders[i] = item;
881881
}
882-
render.t.c?.C || render.E(render.t, render.s);
882+
render.u.c?.s || render.E(render.u, render.t);
883883
}
884884
!(function () {
885885
for (let scope of pendingScopes) scope.f = 0;
886886
pendingScopes = [];
887887
})();
888888
}
889889
function comparePendingRenders(a, b) {
890-
return a.u - b.u;
890+
return a.x - b.x;
891891
}
892892
function resetAbortSignal(scope, id) {
893893
let ctrl = scope.g?.[id];
@@ -983,13 +983,13 @@ function createBranch($global, renderer, parentScope, parentNode) {
983983
let branch = createScope($global),
984984
parentBranch = parentScope?.c;
985985
return (
986-
(branch._ = renderer.x || parentScope),
986+
(branch._ = renderer.y || parentScope),
987987
(branch.c = branch),
988988
parentBranch
989-
? ((branch.y = parentBranch.y + 1),
989+
? ((branch.z = parentBranch.z + 1),
990990
(branch.q = parentBranch),
991991
(parentBranch.j ||= new Set()).add(branch))
992-
: (branch.y = 1),
992+
: (branch.z = 1),
993993
renderer.k?.(branch, parentNode.namespaceURI),
994994
branch
995995
);
@@ -1032,7 +1032,7 @@ function createContent(id, template, rawWalks, setup, getArgs) {
10321032
return (owner) => ({
10331033
d: id,
10341034
k: init2,
1035-
x: owner,
1035+
y: owner,
10361036
get h() {
10371037
return (args ||= getArgs?.());
10381038
},
@@ -1102,10 +1102,22 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
11021102
loopScopeAccessor = ownerLoopNodeAccessor + "!",
11031103
loopScopeMapAccessor = ownerLoopNodeAccessor + "(",
11041104
ownerSignal = (ownerScope) => {
1105-
for (let scope of ownerScope[loopScopeAccessor] ||
1106-
ownerScope[loopScopeMapAccessor]?.values() ||
1107-
[])
1108-
scope.f || queueRender(scope, childSignal, -1);
1105+
let scopes =
1106+
ownerScope[loopScopeAccessor] ||
1107+
ownerScope[loopScopeMapAccessor]?.values() ||
1108+
[],
1109+
[firstScope] = scopes;
1110+
firstScope &&
1111+
queueRender(
1112+
ownerScope,
1113+
() => {
1114+
for (let scope of scopes)
1115+
!scope.f && !scope.s && childSignal(scope);
1116+
},
1117+
-1,
1118+
0,
1119+
firstScope.d,
1120+
);
11091121
};
11101122
return (ownerSignal._ = childSignal), ownerSignal;
11111123
}
@@ -1521,7 +1533,7 @@ var classIdToBranch = new Map(),
15211533
branch
15221534
? (existing = !0)
15231535
: (branch = component.scope =
1524-
createBranch(out.global, renderer, renderer.x, document.body)),
1536+
createBranch(out.global, renderer, renderer.y, document.body)),
15251537
applyArgs(branch, args);
15261538
})),
15271539
!existing)

packages/runtime-tags/src/dom/signals.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,25 @@ export function loopClosure<T>(
9797
const loopScopeMapAccessor =
9898
ownerLoopNodeAccessor + AccessorChar.LoopScopeMap;
9999
const ownerSignal = (ownerScope: Scope) => {
100-
for (const scope of ownerScope[loopScopeAccessor] ||
100+
const scopes =
101+
ownerScope[loopScopeAccessor] ||
101102
ownerScope[loopScopeMapAccessor]?.values() ||
102-
[]) {
103-
if (!scope.___pending) {
104-
queueRender(scope, childSignal, -1);
105-
}
103+
[];
104+
const [firstScope] = scopes;
105+
if (firstScope) {
106+
queueRender(
107+
ownerScope,
108+
() => {
109+
for (const scope of scopes) {
110+
if (!scope.___pending && !scope.___destroyed) {
111+
childSignal(scope);
112+
}
113+
}
114+
},
115+
-1,
116+
0,
117+
firstScope.___id,
118+
);
106119
}
107120
};
108121
ownerSignal._ = childSignal;

0 commit comments

Comments
 (0)