0
0
Vueframework~8 mins

Computed vs method performance in Vue - Performance Comparison

Choose your learning style9 modes available
Performance: Computed vs method performance
MEDIUM IMPACT
This affects how fast Vue updates and renders reactive data on the page during user interaction.
Displaying a reactive value that depends on other reactive data
Vue
export default {
  data() {
    return { count: 0 };
  },
  computed: {
    doubled() {
      return this.count * 2;
    }
  }
}
Computed caches the result and only recalculates when 'count' changes, reducing unnecessary work.
📈 Performance GainReduces recalculations to only when dependencies change, improving input responsiveness (INP).
Displaying a reactive value that depends on other reactive data
Vue
export default {
  data() {
    return { count: 0 };
  },
  methods: {
    doubled() {
      return this.count * 2;
    }
  }
}
The method runs every time the component re-renders, causing repeated calculations even if the data hasn't changed.
📉 Performance CostTriggers recalculation on every render, increasing CPU usage and slowing interaction responsiveness.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Method for reactive valueNo extra DOM nodesMultiple recalculations trigger more JS workNormal paint cost[X] Bad
Computed property for reactive valueNo extra DOM nodesRecalculates only on dependency changeNormal paint cost[OK] Good
Rendering Pipeline
Vue tracks reactive dependencies for computed properties, so it recalculates only when needed. Methods run fresh every render, causing more work in the rendering pipeline.
JavaScript Execution
Style Calculation
Layout
Paint
⚠️ BottleneckJavaScript Execution due to repeated calculations in methods
Core Web Vital Affected
INP
This affects how fast Vue updates and renders reactive data on the page during user interaction.
Optimization Tips
1Use computed properties for values derived from reactive data to cache results.
2Avoid methods for reactive display logic that runs on every render.
3Check performance in DevTools to see if recalculations are excessive.
Performance Quiz - 3 Questions
Test your performance knowledge
Which Vue feature caches reactive data to avoid unnecessary recalculations?
AMethods
BComputed properties
CWatchers
DDirect DOM manipulation
DevTools: Performance
How to check: Record a performance profile while interacting with the component. Look for repeated JavaScript function calls for methods vs fewer calls for computed properties.
What to look for: High CPU time spent in method functions indicates poor performance; fewer recalculations with computed show better efficiency.