Measure runtime performance in Vue.js apps
In the last tip we talked about how to improve performance in large lists. But still we haven’t measure how much it really improved.
We can do so by using the Performance tab in Chrome DevTools. But in order to have accurate data, we must activate performance mode on our Vue app.
We can do that by setting the global, in our
main.js file or in a plugin in the case of Nuxt:
Vue.config.performance = true;
Or if you have your
NODE_ENV env variable set correctly, you could use it to set it in non-production environments:
const isDev = process.env.NODE_ENV !== "production"; Vue.config.performance = isDev;
That will activate the User Timing API that Vue uses internally to mark the components performance.
From the last tip, I’ve created this codesandbox. Open it and hit the reload button from the performance tab on Chrome DevTools:
That will record the page load performance. And thanks to the
Vue.config.performance setting that you can see set on
main.js you’ll be able to see a User Timing section on the profiling:
In there, you’ll find 3 metrics:
- Init: time it takes to create the component instance
- Render: time to create the VDom structure
- Patch: time to apply the VDom structure to the real DOM
Back to the curiosity, the results of the previous tip are the following: the normal component takes 417ms to initalize:
While the non-reactive one using
Object.freeze takes 3.9ms:
Of course this can vary a little from run to run, but still the difference must be quite huge. Since the reactivity issue happens when the component is created, you’ll see that difference in the init part of the Reactive and NoReactive components.
See you next week.
Do you want to sponsor a VueDose tip? Send an email to firstname.lastname@example.org and have more info!
Start saving time and get a tip about the Vue ecosystem every week, right in your inbox.