Vue 3 app.config.performance Property
app.config.performance is a very useful configuration property that allows developers to enable or disable performance tracking.
app.config.performance is a global configuration option in Vue 3 used to control whether performance tracking is enabled. By default, this property is off (false). When set to true , Vue will track component rendering performance in development mode and output the related performance data to the browser's developer tools.
How to Enable app.config.performance?
Enabling app.config.performance is very simple. You can configure it when creating the Vue application instance:
Example
import
{
createApp
}
from
'vue'
;
import
App from
'./App.vue'
;
const
app
=
createApp
(
App
)
;
// enable performance tracking
app.
config
.
performance
=
true
;
app.
mount
(
'#app'
)
;
In the code above, we set app.config.performance to true, which enables the performance tracking feature.
The Role of Performance Tracking
After enabling performance tracking, Vue will record the following key performance metrics in development mode:
- Component render time: Vue records the render time of each component, including initial render and update render.
- Lifecycle hook execution time: Vue records the execution time of each lifecycle hook (such as
mounted,updatedand others). - Virtual DOM operations: Vue records the time spent creating, updating, and destroying the virtual DOM.
These performance data will help you better understand the application's performance bottlenecks and optimize accordingly.
Use Cases
app.config.performance It is very useful in the following scenarios:
- Performance optimization: When you find the application running slowly in certain situations, you can enable performance tracking to find out which components or operations are causing the performance issues.
- Debugging complex components: When dealing with complex components, performance tracking helps you understand the execution of each lifecycle hook, enabling better debugging.
- Performance monitoring: During development, continuously monitoring application performance helps you promptly detect and resolve potential performance issues.
Notes
- Development mode:
app.config.performanceOnly takes effect in development mode. In production mode, this configuration is ignored to avoid unnecessary performance overhead. - Browser support: Performance tracking relies on the browser's developer tools, so make sure you are using a modern browser that supports this feature.
Vue 3 Global API