]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: optimize public properties access on componentProxy
authorEvan You <yyx990803@gmail.com>
Thu, 19 Dec 2019 19:19:47 +0000 (14:19 -0500)
committerEvan You <yyx990803@gmail.com>
Thu, 19 Dec 2019 19:19:58 +0000 (14:19 -0500)
packages/runtime-core/src/componentProxy.ts

index cfcc27264faccc0bdb422a76201417c15706fea9..dbdbe894060a6192dd2d709f0c607c68bc13e698 100644 (file)
@@ -94,29 +94,31 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
     // is the multiple hasOwn() calls. It's much faster to do a simple property
     // access on a plain object, so we use an accessCache object (with null
     // prototype) to memoize what access type a key corresponds to.
-    const n = accessCache![key]
-    if (n !== undefined) {
-      switch (n) {
-        case AccessTypes.DATA:
-          return data[key]
-        case AccessTypes.CONTEXT:
-          return renderContext[key]
-        case AccessTypes.PROPS:
-          return propsProxy![key]
+    if (key[0] !== '$') {
+      const n = accessCache![key]
+      if (n !== undefined) {
+        switch (n) {
+          case AccessTypes.DATA:
+            return data[key]
+          case AccessTypes.CONTEXT:
+            return renderContext[key]
+          case AccessTypes.PROPS:
+            return propsProxy![key]
+        }
+      } else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
+        accessCache![key] = AccessTypes.DATA
+        return data[key]
+      } else if (hasOwn(renderContext, key)) {
+        accessCache![key] = AccessTypes.CONTEXT
+        return renderContext[key]
+      } else if (hasOwn(props, key)) {
+        // 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 (data !== EMPTY_OBJ && hasOwn(data, key)) {
-      accessCache![key] = AccessTypes.DATA
-      return data[key]
-    } else if (hasOwn(renderContext, key)) {
-      accessCache![key] = AccessTypes.CONTEXT
-      return renderContext[key]
-    } else if (hasOwn(props, key)) {
-      // 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]
     }
 
     // public $xxx properties & user-attached properties (sink)