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