perf: further tweak accessCache
This commit is contained in:
parent
7305f693b1
commit
d179918001
@ -258,7 +258,7 @@ export function setupStatefulComponent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 0. create render proxy property access cache
|
// 0. create render proxy property access cache
|
||||||
instance.accessCache = Object.create(null)
|
instance.accessCache = {}
|
||||||
// 1. create render proxy
|
// 1. create render proxy
|
||||||
instance.renderProxy = new Proxy(instance, PublicInstanceProxyHandlers)
|
instance.renderProxy = new Proxy(instance, PublicInstanceProxyHandlers)
|
||||||
// 2. create props proxy
|
// 2. create props proxy
|
||||||
|
@ -56,7 +56,7 @@ const enum AccessTypes {
|
|||||||
|
|
||||||
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
|
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
|
||||||
get(target: ComponentInternalInstance, key: string) {
|
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
|
// 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
|
// 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
|
// is the multiple hasOwn() calls. It's much faster to do a simple property
|
||||||
@ -79,7 +79,10 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
|
|||||||
accessCache[key] = AccessTypes.CONTEXT
|
accessCache[key] = AccessTypes.CONTEXT
|
||||||
return renderContext[key]
|
return renderContext[key]
|
||||||
} else if (hasOwn(props, 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 the value from propsProxy for ref unwrapping and readonly
|
||||||
return propsProxy![key]
|
return propsProxy![key]
|
||||||
} else if (key === '$el') {
|
} else if (key === '$el') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user