Performance: Why component patterns matter
HIGH IMPACT
This affects how fast the page loads and how smoothly the app responds to user actions by controlling rendering and updates.
<script setup> const items = ref(Array(1000).fill(0)) </script> <template> <div> <ItemComponent v-for="(item, index) in items" :key="index" :item="item" /> </div> </template> <script> export default { props: ['item'], setup() { // use shallow reactive or memoized computed to avoid unnecessary updates } } </script>
<script setup> const items = ref(Array(1000).fill(0)) </script> <template> <div> <ItemComponent v-for="(item, index) in items" :key="index" :item="item" /> </div> </template> <script> export default { props: ['item'], setup() { // heavy computed or watchers inside each item } } </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy reactive dependencies in many child components | High (many nodes updated) | High (many reflows) | High (many paints) | [X] Bad |
| Memoized props and shallow reactive data | Low (only changed nodes) | Low (few reflows) | Low (minimal paints) | [OK] Good |