This commit is contained in:
zhangenming 2024-09-12 09:12:28 +00:00
parent d0b513eb46
commit cd2a0d0b3a
1 changed files with 6 additions and 20 deletions

View File

@ -5,19 +5,18 @@ import {
} from './component' } from './component'
import { devtoolsPerfEnd, devtoolsPerfStart } from './devtools' import { devtoolsPerfEnd, devtoolsPerfStart } from './devtools'
let supported: boolean const perf = typeof window !== 'undefined' && window.performance
let perf: Performance const timer = perf ? () => perf.now() : Date.now
export function startMeasure( export function startMeasure(
instance: ComponentInternalInstance, instance: ComponentInternalInstance,
type: string, type: string,
): void { ): void {
if (instance.appContext.config.performance && isSupported()) { if (instance.appContext.config.performance && perf) {
perf.mark(`vue-${type}-${instance.uid}`) perf.mark(`vue-${type}-${instance.uid}`)
} }
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now()) devtoolsPerfStart(instance, type, timer())
} }
} }
@ -25,7 +24,7 @@ export function endMeasure(
instance: ComponentInternalInstance, instance: ComponentInternalInstance,
type: string, type: string,
): void { ): void {
if (instance.appContext.config.performance && isSupported()) { if (instance.appContext.config.performance && perf) {
const startTag = `vue-${type}-${instance.uid}` const startTag = `vue-${type}-${instance.uid}`
const endTag = startTag + `:end` const endTag = startTag + `:end`
perf.mark(endTag) perf.mark(endTag)
@ -39,19 +38,6 @@ export function endMeasure(
} }
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now()) devtoolsPerfEnd(instance, type, timer())
} }
} }
function isSupported() {
if (supported !== undefined) {
return supported
}
if (typeof window !== 'undefined' && window.performance) {
supported = true
perf = window.performance
} else {
supported = false
}
return supported
}