Performance: Pinia vs Vuex comparison
MEDIUM IMPACT
This affects the app's state management performance, impacting interaction responsiveness and bundle size.
import { defineStore } from 'pinia'; const useCounterStore = defineStore('counter', { state: () => ({ count: 0 }), actions: { increment() { this.count++ }, incrementAsync() { setTimeout(() => this.increment(), 1000) } } });
import { createStore } from 'vuex'; const store = createStore({ state: () => ({ count: 0 }), mutations: { increment(state) { state.count++ } }, actions: { incrementAsync({ commit }) { setTimeout(() => commit('increment'), 1000) } } });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Vuex | More reactive watchers due to mutations and actions | Multiple reflows possible on complex state changes | Higher paint cost from frequent updates | [!] OK |
| Pinia | Fewer reactive watchers with direct state mutation | Single reflow per state change | Lower paint cost due to optimized updates | [OK] Good |