]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: revert to _isRef for perf
authorEvan You <yyx990803@gmail.com>
Thu, 17 Oct 2019 01:36:17 +0000 (21:36 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 17 Oct 2019 19:02:14 +0000 (15:02 -0400)
Benchmarking shows checking for a plain property is about 4~5x faster
than checking for a Symbol, likely because the Symbol does not fit well
into V8's hidden class model.

packages/reactivity/src/computed.ts
packages/reactivity/src/ref.ts

index 3dc478f61b62a847153a10a1ba5f60e8e898ed67..ec26028b2ed47762c38e4091a5696aca4c36da3b 100644 (file)
@@ -1,5 +1,5 @@
 import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect'
-import { Ref, refSymbol, UnwrapRef } from './ref'
+import { Ref, UnwrapRef } from './ref'
 import { isFunction, NOOP } from '@vue/shared'
 
 export interface ComputedRef<T> extends WritableComputedRef<T> {
@@ -46,7 +46,7 @@ export function computed<T>(
     }
   })
   return {
-    [refSymbol]: true,
+    _isRef: true,
     // expose effect so computed can be stopped
     effect: runner,
     get value() {
index 7fec6ffbfda6088ad753139c50009e0cc3d2eff0..24fabbc869ef33ec1544051e7764fe46da8e75f0 100644 (file)
@@ -4,10 +4,8 @@ import { isObject } from '@vue/shared'
 import { reactive } from './reactive'
 import { ComputedRef } from './computed'
 
-export const refSymbol = Symbol(__DEV__ ? 'refSymbol' : '')
-
 export interface Ref<T = any> {
-  [refSymbol]: true
+  _isRef: true
   value: UnwrapRef<T>
 }
 
@@ -21,7 +19,7 @@ export function ref(raw: any) {
   }
   raw = convert(raw)
   const v = {
-    [refSymbol]: true,
+    _isRef: true,
     get value() {
       track(v, OperationTypes.GET, '')
       return raw
@@ -35,7 +33,7 @@ export function ref(raw: any) {
 }
 
 export function isRef(v: any): v is Ref {
-  return v ? v[refSymbol] === true : false
+  return v ? v._isRef === true : false
 }
 
 export function toRefs<T extends object>(
@@ -53,7 +51,7 @@ function toProxyRef<T extends object, K extends keyof T>(
   key: K
 ): Ref<T[K]> {
   return {
-    [refSymbol]: true,
+    _isRef: true,
     get value(): any {
       return object[key]
     },