feat: add Value.Equal bail-out check before reconciliation

Add TypeBox Value.Equal deep-comparison as first optimization layer
in reconcileProps. When a fiber's cached node is deep-equal to the
next node, skip prepareUpdate, commitUpdate, and children
reconciliation entirely. New cachedNode field on Fiber stores the
last reconciled node for comparison.
This commit is contained in:
2026-05-18 17:25:02 +00:00
parent 1e0abb0900
commit 23db3775ad
8 changed files with 283 additions and 41 deletions

View File

@@ -1,4 +1,5 @@
import { effect } from "@preact/signals-core";
import { Value } from "@alkdev/typebox/value";
import type { Fiber, Effect } from "./fiber.js";
import type { HostConfig } from "./config.js";
import type { UNode, UElement } from "../core/schema.js";
@@ -59,6 +60,10 @@ export function reconcileProps<I>(
host: HostConfig<string, I, unknown>,
ctx: unknown,
): void {
if (fiber.cachedNode !== null && Value.Equal(fiber.cachedNode, nextNode)) {
return;
}
if (isUPrimitive(nextNode)) {
if (fiber.tag === "#text") {
const text = nextNode === null ? "" : String(nextNode);
@@ -78,6 +83,7 @@ export function reconcileProps<I>(
}
}
}
fiber.cachedNode = nextNode;
return;
}
@@ -87,6 +93,7 @@ export function reconcileProps<I>(
for (let i = 0; i < count; i++) {
reconcileProps(fiber.children[i]!, rootChildren[i]!, host, ctx);
}
fiber.cachedNode = nextNode;
return;
}
@@ -96,6 +103,7 @@ export function reconcileProps<I>(
const component = el.type as (props: Record<string, unknown>) => UNode;
const out = component({ ...el.props, children: el.children });
reconcileProps(fiber, out, host, ctx);
fiber.cachedNode = nextNode;
return;
}
@@ -120,6 +128,7 @@ export function reconcileProps<I>(
for (let i = 0; i < count; i++) {
reconcileProps(fiber.children[i]!, el.children[i]!, host, ctx);
}
fiber.cachedNode = nextNode;
}
export function commitEffects<I>(