--- title: Avoid Excessive Component Abstraction in Large Lists impact: MEDIUM impactDescription: Each component instance has memory and render overhead - abstractions multiply this in lists type: efficiency tags: [vue3, performance, components, abstraction, lists, optimization] --- # Avoid Excessive Component Abstraction in Large Lists **Impact: MEDIUM** - Component instances are more expensive than plain DOM nodes. While abstractions improve code organization, unnecessary nesting creates overhead. In large lists, this overhead multiplies - 100 items with 3 levels of abstraction means 300+ component instances instead of 100. Don't avoid abstraction entirely, but be mindful of component depth in frequently-rendered elements like list items. ## Task Checklist - [ ] Review list item components for unnecessary wrapper components - [ ] Consider flattening component hierarchies in hot paths - [ ] Use native elements when a component adds no value - [ ] Profile component counts using Vue DevTools - [ ] Focus optimization efforts on the most-rendered components **Incorrect:** ```vue ``` **Correct:** ```vue ``` ## When Abstraction Is Still Worth It ```vue ``` ## Measuring Component Overhead ```javascript // In development, profile component counts import { onMounted, getCurrentInstance } from 'vue' onMounted(() => { const instance = getCurrentInstance() let count = 0 function countComponents(vnode) { if (vnode.component) count++ if (vnode.children) { vnode.children.forEach(child => { if (child.component || child.children) countComponents(child) }) } } // Use Vue DevTools instead for accurate counts console.log('Check Vue DevTools Components tab for instance counts') }) ``` ## Alternatives to Wrapper Components ```vue {{ content }}
``` ## Impact Calculation | List Size | Components per Item | Total Instances | Memory Impact | |-----------|---------------------|-----------------|---------------| | 100 items | 1 (flat) | 100 | Baseline | | 100 items | 3 (nested) | 300 | ~3x memory | | 100 items | 5 (deeply nested) | 500 | ~5x memory | | 1000 items | 1 (flat) | 1000 | High | | 1000 items | 5 (deeply nested) | 5000 | Very High | ## Reference - [Vue.js Performance - Avoid Unnecessary Component Abstractions](https://vuejs.org/guide/best-practices/performance.html#avoid-unnecessary-component-abstractions)