From 07609a91e77b2b106859051acc14cf44ca580206 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Fri, 4 Sep 2026 21:16:25 +0200 Subject: [PATCH] perf: diff single-child render results without a wrapper array diff() and diffElementNodes() wrapped every non-array render result in a fresh [result] array before calling diffChildren(). The #2618 statistics put exactly-one-child at 84% of all children diffs, so that is one throwaway allocation per component and per element on nearly every update. diffChildren now accepts the bare value and constructNewChildrenArray reads it directly. Core -6 B gz / -5 B br. Local paired bench (playwright, interleaved): text-update -3..-6% warm, hydrate1k -3.5% cold, create/replace within noise. --- src/diff/children.js | 4 ++-- src/diff/index.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/diff/children.js b/src/diff/children.js index ddf901a298..562f6f8f30 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -71,7 +71,7 @@ export function diffChildren( /** @type {VNode[]} */ let oldChildren = oldParentVNode._children || EMPTY_ARR; - let newChildrenLength = renderResult.length; + let newChildrenLength = isArray(renderResult) ? renderResult.length : 1; oldDom = constructNewChildrenArray( newParentVNode, @@ -184,7 +184,7 @@ function constructNewChildrenArray( for (i = 0; i < newChildrenLength; i++) { // @ts-expect-error We are reusing the childVNode variable to hold both the // pre and post normalized childVNode - childVNode = renderResult[i]; + childVNode = isArray(renderResult) ? renderResult[i] : renderResult; if ( childVNode == NULL || diff --git a/src/diff/index.js b/src/diff/index.js index 951dfb998d..e0b36aba37 100644 --- a/src/diff/index.js +++ b/src/diff/index.js @@ -334,7 +334,7 @@ export function diff( oldDom = diffChildren( parentDom, - isArray(renderResult) ? renderResult : [renderResult], + renderResult, newVNode, oldVNode, globalContext, @@ -677,7 +677,7 @@ function diffElementNodes( diffChildren( parentDom, - isArray(newChildren) ? newChildren : [newChildren], + newChildren, newVNode, oldVNode, globalContext,