From 520af9787b54955e2ae883679d241f2013271df8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 21 Oct 2019 12:24:19 -0400 Subject: [PATCH] perf: skip normalizeVNode in optimized mode --- packages/runtime-core/src/createRenderer.ts | 45 +++++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/packages/runtime-core/src/createRenderer.ts b/packages/runtime-core/src/createRenderer.ts index 9d2fc51e..f2bc0715 100644 --- a/packages/runtime-core/src/createRenderer.ts +++ b/packages/runtime-core/src/createRenderer.ts @@ -319,7 +319,8 @@ export function createRenderer< anchor, parentComponent, parentSuspense, - isSVG + isSVG, + optimized ) } else { patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized) @@ -335,7 +336,8 @@ export function createRenderer< anchor: HostNode | null, parentComponent: ComponentInternalInstance | null, parentSuspense: HostSuspenseBoundary | null, - isSVG: boolean + isSVG: boolean, + optimized: boolean ) { const tag = vnode.type as string isSVG = isSVG || tag === 'svg' @@ -359,7 +361,8 @@ export function createRenderer< null, parentComponent, parentSuspense, - isSVG + isSVG, + optimized || vnode.dynamicChildren !== null ) } hostInsert(el, container, anchor) @@ -377,10 +380,13 @@ export function createRenderer< parentComponent: ComponentInternalInstance | null, parentSuspense: HostSuspenseBoundary | null, isSVG: boolean, + optimized: boolean, start: number = 0 ) { for (let i = start; i < children.length; i++) { - const child = (children[i] = normalizeVNode(children[i])) + const child = optimized + ? (children[i] as HostVNode) + : (children[i] = normalizeVNode(children[i])) patch( null, child, @@ -388,7 +394,8 @@ export function createRenderer< anchor, parentComponent, parentSuspense, - isSVG + isSVG, + optimized ) } } @@ -620,7 +627,8 @@ export function createRenderer< fragmentEndAnchor, parentComponent, parentSuspense, - isSVG + isSVG, + optimized ) } else { patchChildren( @@ -662,7 +670,8 @@ export function createRenderer< null, parentComponent, parentSuspense, - isSVG + isSVG, + optimized ) } } else if (__DEV__) { @@ -1337,7 +1346,8 @@ export function createRenderer< anchor, parentComponent, parentSuspense, - isSVG + isSVG, + optimized ) } } @@ -1361,7 +1371,9 @@ export function createRenderer< const commonLength = Math.min(oldLength, newLength) let i for (i = 0; i < commonLength; i++) { - const nextChild = (c2[i] = normalizeVNode(c2[i])) + const nextChild = optimized + ? (c2[i] as HostVNode) + : (c2[i] = normalizeVNode(c2[i])) patch( c1[i], nextChild, @@ -1385,6 +1397,7 @@ export function createRenderer< parentComponent, parentSuspense, isSVG, + optimized, commonLength ) } @@ -1411,7 +1424,9 @@ export function createRenderer< // (a b) d e while (i <= e1 && i <= e2) { const n1 = c1[i] - const n2 = (c2[i] = normalizeVNode(c2[i])) + const n2 = optimized + ? (c2[i] as HostVNode) + : (c2[i] = normalizeVNode(c2[i])) if (isSameType(n1, n2)) { patch( n1, @@ -1434,7 +1449,9 @@ export function createRenderer< // d e (b c) while (i <= e1 && i <= e2) { const n1 = c1[e1] - const n2 = (c2[e2] = normalizeVNode(c2[e2])) + const n2 = optimized + ? (c2[i] as HostVNode) + : (c2[e2] = normalizeVNode(c2[e2])) if (isSameType(n1, n2)) { patch( n1, @@ -1468,7 +1485,7 @@ export function createRenderer< while (i <= e2) { patch( null, - (c2[i] = normalizeVNode(c2[i])), + optimized ? (c2[i] as HostVNode) : (c2[i] = normalizeVNode(c2[i])), container, anchor, parentComponent, @@ -1505,7 +1522,9 @@ export function createRenderer< // 5.1 build key:index map for newChildren const keyToNewIndexMap: Map = new Map() for (i = s2; i <= e2; i++) { - const nextChild = (c2[i] = normalizeVNode(c2[i])) + const nextChild = optimized + ? (c2[i] as HostVNode) + : (c2[i] = normalizeVNode(c2[i])) if (nextChild.key != null) { if (__DEV__ && keyToNewIndexMap.has(nextChild.key)) { warn(