Lesson 8 of 9 · 20m
Svelte Performance in Production: Less Framework, Same Discipline
Bundle analysis, hydration boundaries, list rendering, images, and why Svelte's small runtime doesn't rescue careless app design.
Svelte gives you a better starting point: less framework JavaScript, targeted DOM updates, and no runtime reconciliation tax. It does not make performance automatic. The usual production killers remain application code, dependency weight, network waterfalls, and DOM quantity.
Measure the artifact before the vibes
npm run build
npx vite-bundle-visualizer distExact commands vary by template, but the habit does not: inspect what actually ships. A markdown editor, charting library, or rich text package can dwarf the entire Svelte runtime. Dynamic imports are still the main lever:
<script>
let editor = $state(null);
async function openEditor() {
const module = await import("$lib/HeavyEditor.svelte");
editor = module.default;
}
</script>Load heavyweight UI at the interaction boundary where it is needed. Do not preload every future panel because the router technically can.
DOM quantity is still the hard floor
{#each rows as row (row.id)}
<IncidentRow {row} />
{/each}Svelte updates exactly what changes, but ten thousand rows still means ten thousand rows of DOM. Virtualize large lists. Key each row with a stable ID so updates and removals do not reuse the wrong component instance. The symptom of a bad key is familiar across frameworks: focus or internal state attached to the wrong visual row.
Hydration is not free
Server-rendered HTML makes first paint fast; hydration then attaches behavior. Keep interactive islands small and let static content stay static. If a mostly static marketing page hydrates a feedback widget, a carousel, and three analytics beacons before interaction, you have recreated heavyweight bootstrapping one small component at a time.
Useful checks:
- WebPageTest or Lighthouse for first load on real mobile hardware assumptions.
- Browser performance panel for long tasks after hydration.
- Server logs for load-function waterfalls; client rendering can't compensate for serial backend latency.
The compiler helps most in hot interactions
Svelte shines in interfaces where small changes happen frequently: dashboards, editors, games, collaborative UI, filters, and local-first tools. The win is not just bytes; it is predictable update cost. But a synchronous 80 ms calculation in an event handler still blocks input, no matter what compiled the surrounding component.
Field notes
- Small bundle numbers in blog posts often exclude your actual dependencies. Measure your route, not the starter template.
- Prefer platform features first:
<img loading="lazy">, real links, CSS containment, and HTTP caching beat clever framework code. - A keyed
{#each}block is about identity, not performance cosmetics. Use stable IDs. - Do not move work to the client to make server response metrics look better. Users experience the total time, not your dashboard split.
Was this lesson helpful?