0
0
Vueframework~8 mins

v-for with objects in Vue - Performance & Optimization

Choose your learning style9 modes available
Performance: v-for with objects
MEDIUM IMPACT
This affects rendering speed and DOM update performance when looping over object properties in Vue templates.
Rendering a list of items from an object in Vue
Vue
<template>
  <ul>
    <li v-for="(value, key) in items" :key="key">
      {{ key }}: {{ value }}
    </li>
  </ul>
</template>
Using a stable key (the object property name) lets Vue efficiently patch only changed nodes.
📈 Performance GainReduces reflows to only changed items, improving update speed and interaction responsiveness.
Rendering a list of items from an object in Vue
Vue
<template>
  <ul>
    <li v-for="(value, key) in items" :key="Math.random()">
      {{ key }}: {{ value }}
    </li>
  </ul>
</template>
Using a random key causes Vue to recreate all DOM nodes on each update, triggering full reflows.
📉 Performance CostTriggers full reflow and repaint on every update, blocking rendering for tens of milliseconds on large lists.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
v-for with random keysFull node replacement on each updateTriggers full reflow per updateHigh paint cost due to many node changes[X] Bad
v-for with stable keys (object keys)Only changed nodes updatedMinimal reflows limited to changed itemsLower paint cost with fewer DOM changes[OK] Good
Rendering Pipeline
Vue compiles the v-for directive into a loop that creates DOM nodes for each object property. The key attribute helps Vue track nodes between updates to minimize DOM changes.
Virtual DOM Diffing
DOM Update
Layout
Paint
⚠️ BottleneckDOM Update stage is most expensive when keys are unstable causing full node replacement.
Core Web Vital Affected
INP
This affects rendering speed and DOM update performance when looping over object properties in Vue templates.
Optimization Tips
1Always use stable keys from object properties in v-for loops.
2Avoid generating keys dynamically like Math.random() or index.
3Large objects rendered with v-for should be paginated or virtualized to reduce DOM cost.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of using stable keys in v-for loops over objects?
AIt triggers more reflows
BIt increases the bundle size
CVue can patch only changed nodes, reducing DOM updates
DIt disables Vue reactivity
DevTools: Performance
How to check: Record a performance profile while updating the object data. Look for long scripting and layout times related to DOM updates.
What to look for: High layout and paint times indicate inefficient DOM updates. Stable keys reduce these times.