Skip to content

Commit d179918

Browse files
committed
perf: further tweak accessCache
1 parent 7305f69 commit d179918

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/runtime-core/src/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export function setupStatefulComponent(
258258
}
259259
}
260260
// 0. create render proxy property access cache
261-
instance.accessCache = Object.create(null)
261+
instance.accessCache = {}
262262
// 1. create render proxy
263263
instance.renderProxy = new Proxy(instance, PublicInstanceProxyHandlers)
264264
// 2. create props proxy

packages/runtime-core/src/componentProxy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const enum AccessTypes {
5656

5757
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
5858
get(target: ComponentInternalInstance, key: string) {
59-
const { renderContext, data, props, propsProxy, accessCache } = target
59+
const { renderContext, data, props, propsProxy, accessCache, type } = target
6060
// This getter gets called for every property access on the render context
6161
// during render and is a major hotspot. The most expensive part of this
6262
// is the multiple hasOwn() calls. It's much faster to do a simple property
@@ -79,7 +79,10 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
7979
accessCache[key] = AccessTypes.CONTEXT
8080
return renderContext[key]
8181
} else if (hasOwn(props, key)) {
82-
accessCache[key] = AccessTypes.PROPS
82+
// only cache props access if component has declared (thus stable) props
83+
if (type.props != null) {
84+
accessCache[key] = AccessTypes.PROPS
85+
}
8386
// return the value from propsProxy for ref unwrapping and readonly
8487
return propsProxy![key]
8588
} else if (key === '$el') {

0 commit comments

Comments
 (0)