Skip to content

Commit 4a1ed17

Browse files
authored
Merge pull request #4088 from solidjs/claude/project-thread-271xwi
perf(frames): morph skips an identical subtree with one native compare
2 parents 86cf504 + 4ec9f2e commit 4a1ed17

5 files changed

Lines changed: 79 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
Frames morph skips an identical subtree with one native `isEqualNode` compare instead of walking it.

‎packages/web/frames/src/frame-client.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,6 +3025,10 @@ function morphNode(oldNode, newNode, claim, ranges, grafts) {
30253025
// (a rich editor, a chart) or any state the deny-list above can't name.
30263026
// The element stays matched in position; only its interior is frozen.
30273027
if (oldNode.hasAttribute("data-preserve")) return;
3028+
// An identical subtree has nothing to morph: one native compare instead
3029+
// of walking it. Not while slot ranges are indexed for relocation — a
3030+
// skipped subtree would leave its ranges looking unmatched.
3031+
if (!ranges?.size && oldNode.isEqualNode(newNode)) return;
30283032
morphAttributes(oldNode, newNode, claim);
30293033
reconcileChildren(oldNode, newNode, null, null, claim, ranges, grafts);
30303034
} else if (oldNode.data !== newNode.data) {

‎packages/web/test/frames-hole-row-ops.spec.tsx‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,40 @@ describe("row ops on a live For hole", () => {
114114
await done();
115115
});
116116

117+
test("a hole re-sent whole skips identical rows and still lands deep changes", async () => {
118+
const { container, items, send, done } = await mount();
119+
const [a, b, c] = items();
120+
const changed: Node[] = [];
121+
const observer = new MutationObserver(records => {
122+
for (const r of records) changed.push(r.target);
123+
});
124+
observer.observe(container, {
125+
subtree: true,
126+
childList: true,
127+
attributes: true,
128+
characterData: true
129+
});
130+
send({
131+
type: "hole",
132+
key: "lh:0",
133+
html: `<!--lr--><li>a</li><!--lr--><li class="x"><b>b</b></li><!--lr--><li>c</li>`,
134+
digest: "d1"
135+
});
136+
await cycle();
137+
observer.disconnect();
138+
expect(items().map(li => li.outerHTML)).toEqual([
139+
"<li>a</li>",
140+
'<li class="x"><b>b</b></li>',
141+
"<li>c</li>"
142+
]);
143+
expect(items()[0]).toBe(a);
144+
expect(items()[1]).toBe(b);
145+
expect(items()[2]).toBe(c);
146+
// The identical rows were skipped whole: every change is inside row b.
147+
expect(changed.every(n => b.contains(n))).toBe(true);
148+
await done();
149+
});
150+
117151
test("morphs only the changed row, appends and truncates at the tail", async () => {
118152
await prepareTier("wire");
119153
const { items, send, done } = await mount();

‎scripts/size/floor-caps.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
},
1414
"page: base server components (hydrating + dynamic + frames + sf reference)": {
1515
"cap": "34.334 KB",
16-
"minified": 106786
16+
"minified": 106814
1717
},
1818
"page: live server components (base + live/GET + action + isPending/latest)": {
1919
"cap": "38.146 KB",
20-
"minified": 119009
20+
"minified": 119037
2121
},
2222
"server: floor (getRequestEvent + isServer)": {
2323
"cap": "1.34 KB",

‎scripts/size/scenarios.js‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4334,8 +4334,14 @@ module.exports = [
43344334
// re-inserted per tick -> 0; main-thread busy 771-910 -> 571-705 ms/s.
43354335
// Measured at 11,856 B brotli / 35,466 B minified. Cap set to that
43364336
// measurement.
4337-
limit: "11.856 KB",
4338-
capMinified: 35466,
4337+
// Morph skips an identical subtree (2026-10-15): +28 B minified. A
4338+
// whole-range morph walked every unchanged element in JS; one native
4339+
// `isEqualNode` compare now skips it. server-dbmon, row ops off, 4x CPU:
4340+
// busy 340-429 -> 214-339 ms/s at 100 rows / 10%; 400 rows no longer
4341+
// saturates. Measured at
4342+
// 11,873 B brotli / 35,494 B minified; cap set to that measurement. Accepted by the maintainer (2026-10-15).
4343+
limit: "11.873 KB",
4344+
capMinified: 35494,
43394345
alias: framesAlias,
43404346
external: framesExternal
43414347
},
@@ -4650,6 +4656,12 @@ module.exports = [
46504656
// recorded minified (floor-caps.json; the brotli cap is unchanged), re-recorded at what the tree measures after
46514657
// createDeferred (#4067) landed in the signals core. Accepted by the
46524658
// maintainer (2026-10-15, "Ratchet up").
4659+
// Morph skips an identical subtree (2026-10-15): +28 B minified. A
4660+
// whole-range morph walked every unchanged element in JS; one native
4661+
// `isEqualNode` compare now skips it. server-dbmon, row ops off, 4x CPU:
4662+
// busy 340-429 -> 214-339 ms/s at 100 rows / 10%; 400 rows no longer
4663+
// saturates. Size-Exception:
4664+
// recorded minified (floor-caps.json) 106,786 -> 106,814; brotli cap unchanged. Accepted by the maintainer (2026-10-15).
46534665
limit: floorCaps["page: base server components (hydrating + dynamic + frames + sf reference)"],
46544666
capMinified:
46554667
floorMinified["page: base server components (hydrating + dynamic + frames + sf reference)"],
@@ -4909,6 +4921,12 @@ module.exports = [
49094921
// recorded minified (floor-caps.json; the brotli cap is unchanged), re-recorded at what the tree measures after
49104922
// createDeferred (#4067) landed in the signals core. Accepted by the
49114923
// maintainer (2026-10-15, "Ratchet up").
4924+
// Morph skips an identical subtree (2026-10-15): +28 B minified. A
4925+
// whole-range morph walked every unchanged element in JS; one native
4926+
// `isEqualNode` compare now skips it. server-dbmon, row ops off, 4x CPU:
4927+
// busy 340-429 -> 214-339 ms/s at 100 rows / 10%; 400 rows no longer
4928+
// saturates. Size-Exception:
4929+
// recorded minified (floor-caps.json) 119,009 -> 119,037; brotli cap unchanged. Accepted by the maintainer (2026-10-15).
49124930
limit: floorCaps["page: live server components (base + live/GET + action + isPending/latest)"],
49134931
capMinified:
49144932
floorMinified["page: live server components (base + live/GET + action + isPending/latest)"],
@@ -5230,8 +5248,14 @@ module.exports = [
52305248
// recorded minified (the brotli cap is unchanged), re-recorded at what the tree measures after
52315249
// createDeferred (#4067) landed in the signals core. Accepted by the
52325250
// maintainer (2026-10-15, "Ratchet up").
5251+
// Morph skips an identical subtree (2026-10-15): +28 B minified. A
5252+
// whole-range morph walked every unchanged element in JS; one native
5253+
// `isEqualNode` compare now skips it. server-dbmon, row ops off, 4x CPU:
5254+
// busy 340-429 -> 214-339 ms/s at 100 rows / 10%; 400 rows no longer
5255+
// saturates. Recorded
5256+
// minified 130,667 -> 130,695; brotli cap unchanged. Accepted by the maintainer (2026-10-15).
52335257
limit: "41.794 KB",
5234-
capMinified: 130667,
5258+
capMinified: 130695,
52355259
alias: pageAlias,
52365260
conditions: solidConditions,
52375261
compile: { hydratable: true }
@@ -5335,8 +5359,14 @@ module.exports = [
53355359
// recorded minified (the brotli cap is unchanged), re-recorded at what the tree measures after
53365360
// createDeferred (#4067) landed in the signals core. Accepted by the
53375361
// maintainer (2026-10-15, "Ratchet up").
5362+
// Morph skips an identical subtree (2026-10-15): +28 B minified. A
5363+
// whole-range morph walked every unchanged element in JS; one native
5364+
// `isEqualNode` compare now skips it. server-dbmon, row ops off, 4x CPU:
5365+
// busy 340-429 -> 214-339 ms/s at 100 rows / 10%; 400 rows no longer
5366+
// saturates. Recorded
5367+
// minified 144,205 -> 144,233; brotli cap unchanged. Accepted by the maintainer (2026-10-15).
53385368
limit: "47.493 KB",
5339-
capMinified: 144205,
5369+
capMinified: 144233,
53405370
alias: pageAlias,
53415371
conditions: solidConditions,
53425372
compile: { hydratable: true }

0 commit comments

Comments
 (0)