Skip to content

Commit 4d227b9

Browse files
committed
turn off perf timeline measuring by default + reduce its impact on dev time perf (fix vuejs#5174)
1 parent a6e1ae0 commit 4d227b9

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

src/core/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const config: Config = {
4848
/**
4949
* Whether to record perf
5050
*/
51-
performance: process.env.NODE_ENV !== 'production',
51+
performance: false,
5252

5353
/**
5454
* Error handler for watcher errors

src/core/instance/init.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* @flow */
22

33
import config from '../config'
4-
import { perf } from '../util/perf'
54
import { initProxy } from './proxy'
65
import { initState } from './state'
76
import { initRender } from './render'
87
import { initEvents } from './events'
8+
import { mark, measure } from '../util/perf'
99
import { initLifecycle, callHook } from './lifecycle'
1010
import { initProvide, initInjections } from './inject'
1111
import { extend, mergeOptions, formatComponentName } from '../util/index'
@@ -15,8 +15,8 @@ let uid = 0
1515
export function initMixin (Vue: Class<Component>) {
1616
Vue.prototype._init = function (options?: Object) {
1717
/* istanbul ignore if */
18-
if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
19-
perf.mark('init')
18+
if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
19+
mark('init')
2020
}
2121

2222
const vm: Component = this
@@ -55,10 +55,10 @@ export function initMixin (Vue: Class<Component>) {
5555
callHook(vm, 'created')
5656

5757
/* istanbul ignore if */
58-
if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
58+
if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
5959
vm._name = formatComponentName(vm, false)
60-
perf.mark('init end')
61-
perf.measure(`${vm._name} init`, 'init', 'init end')
60+
mark('init end')
61+
measure(`${vm._name} init`, 'init', 'init end')
6262
}
6363

6464
if (vm.$options.el) {

src/core/instance/lifecycle.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* @flow */
22

33
import config from '../config'
4-
import { perf } from '../util/perf'
54
import Watcher from '../observer/watcher'
5+
import { mark, measure } from '../util/perf'
66
import { createEmptyVNode } from '../vdom/vnode'
77
import { observerState } from '../observer/index'
88
import { updateComponentListeners } from './events'
@@ -161,19 +161,21 @@ export function mountComponent (
161161

162162
let updateComponent
163163
/* istanbul ignore if */
164-
if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
164+
if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
165165
updateComponent = () => {
166166
const name = vm._name
167167
const startTag = `start ${name}`
168168
const endTag = `end ${name}`
169-
perf.mark(startTag)
169+
170+
mark(startTag)
170171
const vnode = vm._render()
171-
perf.mark(endTag)
172-
perf.measure(`${name} render`, startTag, endTag)
173-
perf.mark(startTag)
172+
mark(endTag)
173+
measure(`${name} render`, startTag, endTag)
174+
175+
mark(startTag)
174176
vm._update(vnode, hydrating)
175-
perf.mark(endTag)
176-
perf.measure(`${name} patch`, startTag, endTag)
177+
mark(endTag)
178+
measure(`${name} patch`, startTag, endTag)
177179
}
178180
} else {
179181
updateComponent = () => {

src/core/util/perf.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import { inBrowser } from './env'
22

3-
export let perf
3+
export let mark
4+
export let measure
45

56
if (process.env.NODE_ENV !== 'production') {
6-
perf = inBrowser && window.performance
7-
if (perf && (!perf.mark || !perf.measure)) {
8-
perf = undefined
7+
const perf = inBrowser && window.performance
8+
if (
9+
perf &&
10+
perf.mark &&
11+
perf.measure &&
12+
perf.clearMarks &&
13+
perf.clearMeasures
14+
) {
15+
mark = tag => perf.mark(tag)
16+
measure = (name, startTag, endTag) => {
17+
perf.measure(name, startTag, endTag)
18+
perf.clearMarks(startTag)
19+
perf.clearMarks(endTag)
20+
perf.clearMeasures(name)
21+
}
922
}
1023
}

src/entries/web-runtime-with-compiler.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import Vue from './web-runtime'
44
import config from 'core/config'
5-
import { perf } from 'core/util/perf'
65
import { query } from 'web/util/index'
76
import { warn, cached } from 'core/util/index'
7+
import { mark, measure } from 'core/util/perf'
88
import { shouldDecodeNewlines } from 'web/util/compat'
99
import { compileToFunctions } from 'web/compiler/index'
1010

@@ -57,8 +57,8 @@ Vue.prototype.$mount = function (
5757
}
5858
if (template) {
5959
/* istanbul ignore if */
60-
if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
61-
perf.mark('compile')
60+
if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
61+
mark('compile')
6262
}
6363

6464
const { render, staticRenderFns } = compileToFunctions(template, {
@@ -69,9 +69,9 @@ Vue.prototype.$mount = function (
6969
options.staticRenderFns = staticRenderFns
7070

7171
/* istanbul ignore if */
72-
if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
73-
perf.mark('compile end')
74-
perf.measure(`${this._name} compile`, 'compile', 'compile end')
72+
if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
73+
mark('compile end')
74+
measure(`${this._name} compile`, 'compile', 'compile end')
7575
}
7676
}
7777
}

0 commit comments

Comments
 (0)