Просмотр исходного кода

turn off perf timeline measuring by default + reduce its impact on dev time perf (fix #5174)

Evan You 9 лет назад
Родитель
Сommit
4d227b98d0

+ 1 - 1
src/core/config.js

@@ -48,7 +48,7 @@ const config: Config = {
   /**
    * Whether to record perf
    */
-  performance: process.env.NODE_ENV !== 'production',
+  performance: false,
 
   /**
    * Error handler for watcher errors

+ 6 - 6
src/core/instance/init.js

@@ -1,11 +1,11 @@
 /* @flow */
 
 import config from '../config'
-import { perf } from '../util/perf'
 import { initProxy } from './proxy'
 import { initState } from './state'
 import { initRender } from './render'
 import { initEvents } from './events'
+import { mark, measure } from '../util/perf'
 import { initLifecycle, callHook } from './lifecycle'
 import { initProvide, initInjections } from './inject'
 import { extend, mergeOptions, formatComponentName } from '../util/index'
@@ -15,8 +15,8 @@ let uid = 0
 export function initMixin (Vue: Class<Component>) {
   Vue.prototype._init = function (options?: Object) {
     /* istanbul ignore if */
-    if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
-      perf.mark('init')
+    if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
+      mark('init')
     }
 
     const vm: Component = this
@@ -55,10 +55,10 @@ export function initMixin (Vue: Class<Component>) {
     callHook(vm, 'created')
 
     /* istanbul ignore if */
-    if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
+    if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
       vm._name = formatComponentName(vm, false)
-      perf.mark('init end')
-      perf.measure(`${vm._name} init`, 'init', 'init end')
+      mark('init end')
+      measure(`${vm._name} init`, 'init', 'init end')
     }
 
     if (vm.$options.el) {

+ 10 - 8
src/core/instance/lifecycle.js

@@ -1,8 +1,8 @@
 /* @flow */
 
 import config from '../config'
-import { perf } from '../util/perf'
 import Watcher from '../observer/watcher'
+import { mark, measure } from '../util/perf'
 import { createEmptyVNode } from '../vdom/vnode'
 import { observerState } from '../observer/index'
 import { updateComponentListeners } from './events'
@@ -161,19 +161,21 @@ export function mountComponent (
 
   let updateComponent
   /* istanbul ignore if */
-  if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
+  if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
     updateComponent = () => {
       const name = vm._name
       const startTag = `start ${name}`
       const endTag = `end ${name}`
-      perf.mark(startTag)
+
+      mark(startTag)
       const vnode = vm._render()
-      perf.mark(endTag)
-      perf.measure(`${name} render`, startTag, endTag)
-      perf.mark(startTag)
+      mark(endTag)
+      measure(`${name} render`, startTag, endTag)
+
+      mark(startTag)
       vm._update(vnode, hydrating)
-      perf.mark(endTag)
-      perf.measure(`${name} patch`, startTag, endTag)
+      mark(endTag)
+      measure(`${name} patch`, startTag, endTag)
     }
   } else {
     updateComponent = () => {

+ 17 - 4
src/core/util/perf.js

@@ -1,10 +1,23 @@
 import { inBrowser } from './env'
 
-export let perf
+export let mark
+export let measure
 
 if (process.env.NODE_ENV !== 'production') {
-  perf = inBrowser && window.performance
-  if (perf && (!perf.mark || !perf.measure)) {
-    perf = undefined
+  const perf = inBrowser && window.performance
+  if (
+    perf &&
+    perf.mark &&
+    perf.measure &&
+    perf.clearMarks &&
+    perf.clearMeasures
+  ) {
+    mark = tag => perf.mark(tag)
+    measure = (name, startTag, endTag) => {
+      perf.measure(name, startTag, endTag)
+      perf.clearMarks(startTag)
+      perf.clearMarks(endTag)
+      perf.clearMeasures(name)
+    }
   }
 }

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

@@ -2,9 +2,9 @@
 
 import Vue from './web-runtime'
 import config from 'core/config'
-import { perf } from 'core/util/perf'
 import { query } from 'web/util/index'
 import { warn, cached } from 'core/util/index'
+import { mark, measure } from 'core/util/perf'
 import { shouldDecodeNewlines } from 'web/util/compat'
 import { compileToFunctions } from 'web/compiler/index'
 
@@ -57,8 +57,8 @@ Vue.prototype.$mount = function (
     }
     if (template) {
       /* istanbul ignore if */
-      if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
-        perf.mark('compile')
+      if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
+        mark('compile')
       }
 
       const { render, staticRenderFns } = compileToFunctions(template, {
@@ -69,9 +69,9 @@ Vue.prototype.$mount = function (
       options.staticRenderFns = staticRenderFns
 
       /* istanbul ignore if */
-      if (process.env.NODE_ENV !== 'production' && config.performance && perf) {
-        perf.mark('compile end')
-        perf.measure(`${this._name} compile`, 'compile', 'compile end')
+      if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
+        mark('compile end')
+        measure(`${this._name} compile`, 'compile', 'compile end')
       }
     }
   }