From 7f06981f7c060235a33698cb00f1ecab6a6210bc Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 30 Sep 2019 10:45:50 -0400 Subject: [PATCH] perf: using a _isVNode field is faster than a weakset --- packages/runtime-core/src/vnode.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index ca3670c3..9b4d74cb 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -55,6 +55,7 @@ export type NormalizedChildren = | null export interface VNode { + _isVNode: true type: VNodeTypes props: Record | null key: string | number | null @@ -124,10 +125,8 @@ export function createBlock( return vnode } -const knownVNodes = new WeakSet() - export function isVNode(value: any): boolean { - return knownVNodes.has(value) + return value && value._isVNode } export function createVNode( @@ -172,6 +171,7 @@ export function createVNode( : 0 const vnode: VNode = { + _isVNode: true, type, props, key: (props && props.key) || null, @@ -204,10 +204,6 @@ export function createVNode( trackDynamicNode(vnode) } - if (__DEV__) { - knownVNodes.add(vnode) - } - return vnode } @@ -220,6 +216,7 @@ function trackDynamicNode(vnode: VNode) { export function cloneVNode(vnode: VNode): VNode { return { + _isVNode: true, type: vnode.type, props: vnode.props, key: vnode.key,