Tech Interview RoomStudy guides

Vue.js

How do you optimise performance in a large Vue application?

Advanced · 2 min read · Lesson 11 of 12 in Vue.js

Rendering

  • Keep reactive state small and shaped right: use shallowRef for large lists of immutable objects (API responses) and replace the array instead of mutating deep fields; markRaw third-party instances (maps, charts, editors).
  • Prefer computed over methods in templates: computeds are cached.
  • Keep props stable: pass primitive ids instead of new objects each render, so children do not update unnecessarily.
  • Split big components so updates stay local; Vue re-renders per component.
  • Virtualise long lists (vue-virtual-scroller, TanStack Virtual for Vue).
  • v-memo for huge lists, v-once for static content, v-show for frequent toggles.
  • <KeepAlive> to avoid rebuilding tabs.

Loading

  • Lazy-load routes and heavy components with defineAsyncComponent(() => import(...)).
  • Analyse the bundle; import only what you use from UI libraries (use their resolvers with unplugin-vue-components).
  • SSR or static generation with Nuxt for faster first paint and SEO; lazy hydration (Nuxt hydrate-on-visible, Vue 3.5 hydrateOnVisible for async components) delays hydrating below-the-fold parts.
  • Optimise images, fonts and third-party scripts.

Measuring

Vue DevTools' performance and timeline tabs show component render times; the Chrome Performance panel and Web Vitals show the real user impact.

Example

js
import { shallowRef, defineAsyncComponent, markRaw } from 'vue';

// 10,000 rows from the API: track only the array reference, not every field
const rows = shallowRef([]);
async function load() {
  rows.value = await (await fetch('/api/rows')).json();   // replace, don't mutate
}
function rename(id, name) {
  rows.value = rows.value.map(r => (r.id === id ? { ...r, name } : r));
}

// Heavy editor loaded only when shown
const RichEditor = defineAsyncComponent({
  loader: () => import('./RichEditor.vue'),
  loadingComponent: EditorSkeleton,
  delay: 200,
});

// Third-party instance kept out of reactivity
const map = markRaw(new maplibregl.Map({ container: 'map' }));

Follow-up questions interviewers ask

Try answering each one before you open it.

Why can a deep watcher on a large object be slow?

deep: true must traverse every nested property on each check to collect dependencies. On thousands of objects that is expensive. Watch a specific getter (() => state.filters.query), use a numeric depth (Vue 3.5), or use shallowRef and replace the value so a shallow watch is enough.