Svelte didn't kill the runtime. It shrank it.

By Esteban Trillo7 min readWhy SvelteSvelte

The compiler writes the wiring once. React's runtime does it on every click.
The compiler writes the wiring once. React's runtime does it on every click.

Part 2 of a series on Svelte in 2026. Part 1 made the pitch. This part reads what the compiler writes.

I built part 1’s counter twice, once in Svelte and once in React, and ran vite build on each.

Counter raw gzip
Svelte 5.57.2 25.39 kB 10.20 kB
React 19.3.1 219.62 kB 68.66 kB
React 19.3.1 + Compiler 219.95 kB 68.85 kB

Ten kilobytes against sixty-nine. That’s the number people screenshot, and it’s true. It also measures almost nothing about the button I wrote.

What it measures is runtime. Svelte ships one too, it’s just a lot smaller than React’s, and the compiler is the reason. To see where those 10 kB go, you have to read the code the compiler emits.

What “compiler” means here

React ships a library. Your component is a function, React calls it again on every update, and it diffs the result against the last one. Rich Harris made the case against that in 2018: “diffing isn’t free,” and “the greater overhead is in the components themselves.”1 His alternative was a framework that “knows at build time how things could change in your app, rather than waiting to do the work at run time.”

That’s still the idea in Svelte 5. The docs say it “uses a compiler to turn declarative components written in HTML, CSS and JavaScript” into JavaScript.2 Runes are part of it: they’re “symbols that influence the Svelte compiler.”3 When you write $state(0), you’re giving the compiler an instruction, not calling a function.

Read what the compiler writes

Here’s part 1’s counter again.

Counter.svelte
<script lang="ts">
let count = $state(0);
let doubled = $derived(count * 2);
</script>
<button onclick={() => count++}>
clicked {count} times (doubled: {doubled})
</button>

And here’s what Svelte 5.57.2 turns it into, client side. I ran every compiled snippet here through Prettier and changed nothing else.

Counter.js (compiled)
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
var root = $.from_html(`<button> </button>`);
export default function X($$anchor) {
let count = $.state(0);
let doubled = $.derived(() => $.get(count) * 2);
var button = root();
var text = $.only_child(button);
$.template_effect(() =>
$.set_text(
text,
`clicked ${$.get(count) ?? ""} times (doubled: ${$.get(doubled) ?? ""})`,
),
);
$.delegated("click", button, () => $.update(count));
$.append($$anchor, button);
}
$.delegate(["click"]);

You can read all of it.

  • The HTML is a template. from_html builds the <button> markup once, and root() clones it.
  • The function runs once, at mount. Nothing calls it again.
  • One effect per dynamic bit. The template_effect reads count and doubled, so when either changes, that effect re-runs and sets one text node.
  • One listener for all clicks. delegate puts a single click handler on the root, not one per button.

Now look at the second line: import * as $ from "svelte/internal/client". That’s the runtime. “Svelte has no runtime” gets repeated a lot, and for Svelte 5 it’s wrong. What it has is a small runtime that gets tree-shaken: every $.something in that file is a function from it, and only the ones your components call end up in the bundle.

What that buys you

A small runtime that grows slowly

The counter needed about 10 kB of Svelte runtime. I wanted to know how that floor moves as an app grows, so I wrote a “filterable list” component with props, two pieces of state, a derived list, a keyed loop, nested conditionals, a bound input and a class toggle. Then I generated N distinct copies of it in each framework and rebuilt. The React version uses useMemo for the filter, the way a careful React developer would.

Whole bundle, gzip (kB):

Components Svelte React React + Compiler
1 14.66 68.05 68.47
10 15.47 68.40 69.23
50 18.70 69.91 72.28
100 22.56 71.74 75.74
200 29.59 74.86 82.76

The Svelte runtime went from about 10 kB to about 14 kB once the app used {#each}, {#if}, bind:value and class:. That’s tree-shaking doing its job. React’s floor doesn’t move: React and ReactDOM come in at about 65 kB gzip whether you have one component or two hundred.

That fixed 65 kB is the saving. For a small app, it’s most of the bundle.

Server rendering becomes string building

Ask the compiler for server output (generate: 'server') and the same counter becomes this:

Counter.js (server)
import * as $ from "svelte/internal/server";
export default function X($$renderer) {
let count = 0;
let doubled = $.derived(() => count * 2);
$$renderer.push(
`<button>clicked ${$.escape(count)} times (doubled: ${$.escape(doubled())})</button>`,
);
}

On the server count is a plain variable. There’s no click handler in the output, so nothing can change it. The component is a string with holes in it.

What it costs you, per component

Look at the scaling table again: Svelte’s column grows faster than React’s.

The copies share a lot of structure, so whole-bundle gzip squeezes them and understates the cost of each one. To get a pessimistic number, I built one chunk per component and compressed a single component’s chunk on its own:

One component, alone raw gzip
Svelte 1,101 B 666 B
React 766 B 453 B
React + Compiler 1,301 B 756 B

Per component, Svelte’s output is bigger than plain React’s. That’s the trade. The compiler writes out the DOM work that React’s runtime does generically, and written-out code takes bytes.

So the bundles cross over, eventually. Against plain React, it takes roughly 250 components of this size, by this pessimistic gzip estimate. In a real bundle the gap closes slower: at 200 components, Svelte was still at 29.6 kB and React at 74.9 kB.

deep diveWhere the 250 comes from, and why it's soft

Svelte starts about 53.4 kB lighter (68.05 − 14.66 kB at one component). Each extra component costs Svelte 213 B more than React (666 − 453 B, gzipped alone). 53,390 ÷ 213 ≈ 250.

That’s a worst case. Measured on raw minified size instead, the slope is gentler and the crossover lands near 830 components.

It’s also one synthetic component shape. Components with more markup and less logic would lean one way, and components that are mostly logic would lean the other. Code splitting changes it again, route by route. Treat 250 as “a few hundred,” not a threshold.

A 6-component marketing page and a 1,500-component internal dashboard both move from React to Svelte. Where does the bundle shrink most, as a share of its size?

React has a compiler now too

“Svelte is the one with a compiler” stopped being a fair contrast in October 2025, when React Compiler 1.0 shipped as “a build-time tool that optimizes your React app through automatic memoization.”4

Here’s the same counter through babel-plugin-react-compiler 1.0:

Counter.jsx (React Compiler)
import { c as _c } from "react/compiler-runtime";
import { useState } from "react";
export default function App() {
const $ = _c(4);
const [count, setCount] = useState(0);
const doubled = count * 2;
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => setCount(_temp);
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] !== count || $[2] !== doubled) {
t1 = (
<button onClick={t0}>
clicked {count} times (doubled: {doubled})
</button>
);
$[1] = count;
$[2] = doubled;
$[3] = t1;
} else {
t1 = $[3];
}
return t1;
}
function _temp(c) {
return c + 1;
}

Both are compilers. They compile toward different runtimes.

React Compiler caches inside a function that still runs on every update. The click handler is built once and reused. The JSX is rebuilt only when count or doubled changed, and here count did, so it’s rebuilt and handed to the virtual DOM to diff. The React docs explain the reason for all of it: without memoization, a state change re-renders “that component and all of its children.”5

Svelte’s compiler removes the re-run. There’s no function to call again and nothing to cache.

Click the button and compare what happens again in each:

React

  1. Counter() runsat mountagain
  2. click handler createdat mountagain
  3. JSX / template builtat mountagain
  4. virtual DOM diffat mountagain
  5. button text setat mountagain

React + Compiler

  1. Counter() runsat mountagain
  2. click handler createdat mountno
  3. JSX / template builtat mountagain
  4. virtual DOM diffat mountagain
  5. button text setat mountagain

Svelte

  1. Counter() runsat mountno
  2. click handler createdat mountno
  3. JSX / template builtat mountno
  4. virtual DOM diffat mountno
  5. button text setat mountagain

To be fair to React Compiler, it isn’t trying to make bundles smaller. Meta’s announcement talks about loads and navigations improving “by up to 12%” and some interactions getting “more than 2.5× faster,” and says nothing about size.4 In my test it made each component bigger: 756 B gzipped, more than Svelte’s 666 B. Against React with the compiler on, the bundles never crossed over in this test.

Where the numbers will fool you

  • Hello-world benchmarks measure the runtime floor. Part 1’s counter is mostly runtime. Measure your own app instead: vite build prints the gzip size of every chunk.
  • Code splitting moves the floor around. The crossover math assumes one bundle. With per-route bundles, where the runtime lands and what each route loads both change, so it shifts route by route.
  • “No runtime” is a myth. There’s svelte/internal/client. It’s small, and only what you use gets bundled.
  • The compiler only sees Svelte files. Runes work in .svelte, .svelte.js and .svelte.ts files. Put $state in a plain .ts file and it won’t compile. Part 8 covers shared state in those modules.

The compiler also scopes your CSS, but that’s part 11.

The saving is real, and it’s in one place

Svelte’s compiler buys you a small, tree-shaken runtime in place of React’s fixed 65 kB, and components that run once instead of on every update. It costs you a little more output per component. For most apps, the floor wins by a mile. For a very big single bundle, measure.

If you want the original argument, Rich Harris’s “Virtual DOM is pure overhead” is short and still holds up.1 The Svelte 3 announcement is where “runs at build time” first became the pitch.6

Next: $state, and what “just a variable” hides.

  • Part 3 — What $state hides: one rune, four compiled outputs, and where the deep proxy stops

Footnotes

  1. Rich Harris, Virtual DOM is pure overhead (December 2018). ↩ ↩2

  2. Svelte docs, Overview. ↩

  3. Introducing runes (September 2023). ↩

  4. React team, React Compiler v1.0 (October 2025). ↩ ↩2

  5. React docs, Introduction to React Compiler. ↩

  6. Svelte 3: Rethinking reactivity (April 2019). It says Svelte “runs at build time, converting your components into highly efficient imperative code.” ↩

Piwi hands a single letter to the user at a mailbox; a small note reads no noise.

Get the next one in your inbox

One email when a post goes out, with its sketch. Nothing in between, and one link to leave.

Sign in faster next time?

Add a passkey and skip the email link. Your fingerprint, face or device PIN is enough.