Skip to content

Lesson 7 of 9 · 24m

Vue Performance: Render Cost, Lists, and Bundle Shape

The optimizations that matter in production Vue — stable keys, selective rendering, lazy dependencies, and measuring before adding magic.

Vue's rendering system is efficient enough that most performance problems are self-inflicted: gigantic lists rendered fully, expensive computed values hidden in templates, or entire admin bundles shipped to anonymous visitors. The correct order is measure, reduce work, then optimize update granularity. Not the reverse.

Keys control identity, and identity controls reuse

<UserRow v-for="user in users" :key="user.id" :user="user" />

Never use array index as a key for reorderable or removable rows. The symptoms are familiar: input state sticks to the wrong row, transitions apply to the wrong element, and components are reused with stale local state. Use the domain ID. If the data has no stable identity, fix the data model before optimizing rendering.

Keep expensive work out of render

const visibleRows = computed(() => {
  return rows.value.filter(matchesFilter).sort(sortRows).slice(0, pageSize);
});

Computed caching helps only if dependencies are correct and work is actually necessary. Rendering ten thousand rows and slicing to fifty in the template is still work done too late. Virtualize long lists with a proven library such as vue-virtual-scroller when scrolling performance or DOM size matters.

v-show vs v-if is a cost decision

v-if destroys and recreates the subtree; v-show keeps it mounted and toggles CSS. Frequently toggled UI with expensive initialization often belongs behind v-show. Rarely used heavyweight panels belong behind v-if so they do not consume memory and effects while closed. Do not apply one rule everywhere — choose based on lifecycle cost and frequency.

Async components shrink the initial bundle

import { defineAsyncComponent } from "vue";

const AuditLogPanel = defineAsyncComponent(() =>
  import("./AuditLogPanel.vue"),
);

Route-level code splitting is the first win; component-level splitting is for genuinely heavy optional UI — charting, editors, admin tooling. Pair it with suspense or explicit loading UI. A blank rectangle is technically asynchronous and emotionally broken.

Measure the real problem

Use Vue DevTools timeline and the browser Performance panel. Record a realistic interaction, not a synthetic best case. Common findings are dependency waterfalls, oversized JSON payloads, image decoding, and main-thread work unrelated to Vue at all. If a Vue render takes 4 ms but the network waits 900 ms, memoization is not the fix.

Field notes

  • shallowRef and markRaw matter for huge immutable objects and third-party instances; proxy overhead is real.
  • Avoid creating new object/array literals in templates passed as props when child memoization matters.
  • v-memo is a scalpel for stable lists, not a general replacement for understanding render causes.
  • Compress text responses (gzip or brotli) before doing component micro-optimization; bundle bytes often dominate first paint.

Was this lesson helpful?

Sign in to rate