From: Evan You Date: Fri, 18 Oct 2019 02:29:51 +0000 (-0400) Subject: perf: further tweak accessCache X-Git-Tag: v3.0.0-alpha.0~383 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d179918001e7bf88b0701ab73f982ca1e7626781;p=thirdparty%2Fvuejs%2Fcore.git perf: further tweak accessCache --- diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 9b1fe8a82f..5e8539b8c4 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -258,7 +258,7 @@ export function setupStatefulComponent( } } // 0. create render proxy property access cache - instance.accessCache = Object.create(null) + instance.accessCache = {} // 1. create render proxy instance.renderProxy = new Proxy(instance, PublicInstanceProxyHandlers) // 2. create props proxy diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index bc1a1f5466..87fa22ec8c 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -56,7 +56,7 @@ const enum AccessTypes { export const PublicInstanceProxyHandlers: ProxyHandler = { get(target: ComponentInternalInstance, key: string) { - const { renderContext, data, props, propsProxy, accessCache } = target + const { renderContext, data, props, propsProxy, accessCache, type } = target // This getter gets called for every property access on the render context // during render and is a major hotspot. The most expensive part of this // is the multiple hasOwn() calls. It's much faster to do a simple property @@ -79,7 +79,10 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { accessCache[key] = AccessTypes.CONTEXT return renderContext[key] } else if (hasOwn(props, key)) { - accessCache[key] = AccessTypes.PROPS + // only cache props access if component has declared (thus stable) props + if (type.props != null) { + accessCache[key] = AccessTypes.PROPS + } // return the value from propsProxy for ref unwrapping and readonly return propsProxy![key] } else if (key === '$el') {