--- title: Use v-once and v-memo to Skip Unnecessary Updates impact: MEDIUM impactDescription: v-once skips all future updates for static content; v-memo conditionally memoizes subtrees type: efficiency tags: [vue3, performance, v-once, v-memo, optimization, directives] --- # Use v-once and v-memo to Skip Unnecessary Updates **Impact: MEDIUM** - Vue re-evaluates templates on every reactive change. For content that never changes or changes infrequently, `v-once` and `v-memo` tell Vue to skip updates, reducing render work. Use `v-once` for truly static content and `v-memo` for conditionally-static content in lists. ## Task Checklist - [ ] Apply `v-once` to elements that use runtime data but never need updating - [ ] Apply `v-memo` to list items that should only update on specific condition changes - [ ] Verify memoized content doesn't need to respond to other state changes - [ ] Profile with Vue DevTools to confirm update skipping ## v-once: Render Once, Never Update **Incorrect:** ```vue ``` **Correct:** ```vue ``` ## v-memo: Conditional Memoization for Lists **Incorrect:** ```vue ``` **Correct:** ```vue ``` ## v-memo with Multiple Dependencies ```vue ``` ## v-memo with Empty Array = v-once ```vue ``` ## When NOT to Use These Directives ```vue ``` ## Performance Comparison | Scenario | Without Directive | With v-once/v-memo | |----------|-------------------|-------------------| | Static header, parent re-renders 100x | Re-evaluated 100x | Evaluated 1x | | 1000 items, selection changes | 1000 items re-render | 2 items re-render | | Complex child component | Full re-render | Skipped if memoized | ## Debugging Memoized Components ```vue ``` ## Reference - [Vue.js v-once Directive](https://vuejs.org/api/built-in-directives.html#v-once) - [Vue.js v-memo Directive](https://vuejs.org/api/built-in-directives.html#v-memo) - [Vue.js Performance - Update Optimizations](https://vuejs.org/guide/best-practices/performance.html#update-optimizations)