perf: revert to _isRef for perf
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.
This commit is contained in:
parent
6c80e13986
commit
cdee65aa1b
@ -1,5 +1,5 @@
|
|||||||
import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect'
|
import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect'
|
||||||
import { Ref, refSymbol, UnwrapRef } from './ref'
|
import { Ref, UnwrapRef } from './ref'
|
||||||
import { isFunction, NOOP } from '@vue/shared'
|
import { isFunction, NOOP } from '@vue/shared'
|
||||||
|
|
||||||
export interface ComputedRef<T> extends WritableComputedRef<T> {
|
export interface ComputedRef<T> extends WritableComputedRef<T> {
|
||||||
@ -46,7 +46,7 @@ export function computed<T>(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
[refSymbol]: true,
|
_isRef: true,
|
||||||
// expose effect so computed can be stopped
|
// expose effect so computed can be stopped
|
||||||
effect: runner,
|
effect: runner,
|
||||||
get value() {
|
get value() {
|
||||||
|
@ -4,10 +4,8 @@ import { isObject } from '@vue/shared'
|
|||||||
import { reactive } from './reactive'
|
import { reactive } from './reactive'
|
||||||
import { ComputedRef } from './computed'
|
import { ComputedRef } from './computed'
|
||||||
|
|
||||||
export const refSymbol = Symbol(__DEV__ ? 'refSymbol' : '')
|
|
||||||
|
|
||||||
export interface Ref<T = any> {
|
export interface Ref<T = any> {
|
||||||
[refSymbol]: true
|
_isRef: true
|
||||||
value: UnwrapRef<T>
|
value: UnwrapRef<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +19,7 @@ export function ref(raw: any) {
|
|||||||
}
|
}
|
||||||
raw = convert(raw)
|
raw = convert(raw)
|
||||||
const v = {
|
const v = {
|
||||||
[refSymbol]: true,
|
_isRef: true,
|
||||||
get value() {
|
get value() {
|
||||||
track(v, OperationTypes.GET, '')
|
track(v, OperationTypes.GET, '')
|
||||||
return raw
|
return raw
|
||||||
@ -35,7 +33,7 @@ export function ref(raw: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isRef(v: any): v is Ref {
|
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>(
|
export function toRefs<T extends object>(
|
||||||
@ -53,7 +51,7 @@ function toProxyRef<T extends object, K extends keyof T>(
|
|||||||
key: K
|
key: K
|
||||||
): Ref<T[K]> {
|
): Ref<T[K]> {
|
||||||
return {
|
return {
|
||||||
[refSymbol]: true,
|
_isRef: true,
|
||||||
get value(): any {
|
get value(): any {
|
||||||
return object[key]
|
return object[key]
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user