• Stars
    star
    305
  • Rank 136,879 (Top 3 %)
  • Language
    JavaScript
  • Created over 3 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Comparing generated code size of Vue and Svelte components

Comparing generated code size of Vue and Svelte components

TL;DR

  1. Compiled Svelte component code is 70% heavier than Vue 3 equivalent, and 110% heavier in SSR mode.
  2. It takes ~19 TodoMVC-sized components (13 in SSR scenarios) to offset the framework base runtime size difference between Vue and Svelte.

Methodology

  1. Both frameworks are used to implement a single spec-compliant, functionally-equivalent TodoMVC component.

  2. Components are compiled in isolation using each framework's online SFC compilers

  3. Compiled files are minified using Terser REPL, and then have the ES imports and exports removed. This is because in a bundled app these imports/exports are either not needed or shared between multiple components.

    • Vue: todomvc.vue.min.js
    • Svelte: todomvc.svelte.min.js
  4. Minified files are then compressed w/ gzip and brotli.

    • Vue: todomvc.vue.min.js.gz / todomvc.vue.min.js.brotli
    • Svelte: todomvc.svelte.min.js.gz / todomvc.svelte.min.js.brotli
  5. In addition, in an SSR setting, Svelte needs to compile its components in "hydratable" mode, which results in additional generated code. Steps 2-4 are repeated for Svelte with "hydratable: true" compiler options.

    Vue produces exactly the same code in SSR settings, but imports some additional hydration-specific runtime code (~0.89kb min+brotli).

  6. For each framework, a default Vite app using the component is created and the production build is run (svelte w/ hydratable: false). Each app is also built another time using SSR-enabled settings.

    The default Vite build splits a vendor chunk (= framework runtime code) and an index chunk (= component code).

Results

Vue Vue (SSR) Svelte Svelte (SSR)
Source 3.93kb - 3.31kb -
Compiled w/o imports (min) 2.73kb - 5.01kb (183.52%) 6.59kb (241.39%)
Compiled w/o imports (min+gz) 1.25kb - 2.13kb (170.40%) 2.68kb (214.40%)
Compiled w/o imports (min+brotli) 1.10kb - 1.88kb (170.91%) 2.33kb (211.82%)
Vite component chunk (min+brotli) 1.13kb - 1.95kb (172.26%) 2.41kb (213.27%)
Vite vendor chunk (min+brotli) 16.89kb 17.78kb 1.85kb 2.13kb

Analysis

In client-only mode, the Svelte app imported 1.85kb min+brotli framework code, which is 15.04kb lighter than Vue. This is the base size difference.

However, for the component code, Svelte's min + compressed output size is ~1.7x of the Vue equivalent. In this case, a single component results in 0.78kb of size difference. In SSR scenarios, this ratio goes up further to ~2.1x where a single component results in a 1.23kb size difference.

TodoMVC covers a pretty decent feature range and is generally representative of the components most users build in typical apps. We can reasonably assume that similar size difference would be found in real world scenarios. That is to say, in theory, if an app contains more than 15.04 / 0.78 ~= 19 TodoMVC-sized components, the Svelte app would end up being heavier than the Vue app.

This threshold is even lower in SSR scenarios. In SSR mode, the base difference is 15.65kb but the component count threshold is down to 15.65 / 1.23 ~= 13!

Obviously in real world apps there are many other factors at play: more features would be imported from the frameworks and 3rd party libraries will be used. The size curve would be affected by the percentage of pure component code in a project. However, it would be safe to assume that the more an app is over the 19-components threshold (or 13 in SSR mode, which most non-trivial apps would probably cross), the less likely it is for Svelte to have any real size advantage.

Takeaways

This study isn't meant to show which framework is better - it's strictly focused on analyzing bundle size implications of different framework implementation strategies.

As can be seen from the data, the two frameworks have different sweet spots in terms of bundle size - and it depends a lot on what kind of use case you have. Svelte is still great for one-off components (e.g. wrapped as a custom element), but its size is in fact a disadvantage in medium to large scale applications, especially with SSR.

In a broader sense, this study is meant to showcase how frameworks are picking different balance points on the compile-time vs. runtime spectrum: Vue performs a decent amount of compile-time optimizations on the source format, but opts for a heavier base runtime in return for smaller generated code. Svelte opts for a minimal runtime but with the cost of heavier generated code. Can Svelte further improve its codegen to reduce code output? Can Vue further improve the tree-shaking to make the baseline smaller? Can another framework find an even better balance point? The answer is probably yes to all of these questions - but as long as we can now acknowledge that "framework size" is a much more nuanced topic than comparing the size of Hello World apps, this study has served its purpose.

More Repositories

1

build-your-own-mint

Build your own personal finance analytics using Plaid, Google Sheets and CircleCI.
HTML
2,481
star
2

vue-hooks

Experimental React hooks implementation in Vue
JavaScript
1,595
star
3

pod

Git push deploy for Node.js
JavaScript
1,343
star
4

zoomerang

drop in zoom anything
JavaScript
1,221
star
5

vue-lit

Proof of concept custom elements "framework"
JavaScript
1,109
star
6

HTML5-Clear-v2

HTML5 Clear version 2
JavaScript
948
star
7

vite-vs-next-turbo-hmr

Benchmarking Vite vs. Next + turbopack HMR performance
JavaScript
920
star
8

laravel-vue-cli-3

Example project using Vue CLI 3 with Laravel
PHP
848
star
9

HTML5-Clear

[DEPRECATED] A replica of the Clear iphone app in HTML5
JavaScript
719
star
10

register-service-worker

A script to simplify service worker registration with hooks for common events.
JavaScript
640
star
11

vue-wordle

Wordle built with Vue, aka VVordle
TypeScript
584
star
12

launch-editor

Open file in editor from Node.js.
JavaScript
577
star
13

semi

To semicolon or not to semicolon; that is the question
JavaScript
304
star
14

okie

Dead simple worker threads pool
TypeScript
263
star
15

starz

Count a GitHub user's total stars
JavaScript
145
star
16

circular-json-es6

circular JSON.stringify and JSON.parse, for environments with native ES6 Map
JavaScript
129
star
17

pug-plain-loader

webpack loader that transforms pug templates to plain HTML
JavaScript
116
star
18

release-tag

GitHub action for auto creating a release on tag push
JavaScript
109
star
19

Speech.js

Simple wrapper for Chrome's web speech recognition API
JavaScript
97
star
20

retweeter

Auto retweet from another account using CircleCI scheduled workflows
JavaScript
59
star
21

matrix.js

Featherweight CSS3 3D engine
JavaScript
58
star
22

buble

a fork of buble with some vue-specific hacks, used in vue-template-es2015-compiler
JavaScript
55
star
23

nightwatch-helpers

custom assertions and commands for easier nightwatch tests
JavaScript
53
star
24

shell-task

Proof-of-concept then-able shell commands in node.
JavaScript
46
star
25

creative-html5

A class about JavaScript, html5 and creative coding.
JavaScript
46
star
26

vue-template-explorer

See how vue templates get compiled into render functions under the hood
Vue
45
star
27

QR.js

Simple HTML5 Canvas-based QR Code generation
JavaScript
42
star
28

vue-tsc-3.3-type-repro

Vue
38
star
29

material-color-scheme-es6

Material Theme color scheme tweaked for ES6
JavaScript
32
star
30

semi-sublime

Sublime Text 3 plugin for Semi
Python
32
star
31

vite-pre-transform-test

JavaScript
30
star
32

speech

component for Chrome speech recognition wrapper
JavaScript
29
star
33

webpack-hmr-repro

JavaScript
28
star
34

raveal

Radially reveal an element
JavaScript
27
star
35

cjs-module-lexer-rollup-reexports

JavaScript
26
star
36

roetem

meteor-like experiment with vue and rethinkdb
JavaScript
24
star
37

gulp-component

component plugin for gulp
JavaScript
22
star
38

oxc-node-loader

JavaScript
22
star
39

tucao

吐槽专用
21
star
40

thread-loader-bug

JavaScript
21
star
41

rollup-tostringtag-symbol-conflict

JavaScript
20
star
42

resolve-type-test

TypeScript
20
star
43

browser-audio

Simple cross browser audio player
JavaScript
19
star
44

babel-preset-flow-vue

JavaScript
18
star
45

esbuild-exports-signature-repro

JavaScript
17
star
46

popSlides

javascript popup slideshow plugin based on jQuery
JavaScript
17
star
47

vue

vue bug
HTML
16
star
48

rollup-commonjs-bug

JavaScript
15
star
49

Puzzle-Demo

A slider puzzle game with CSS3 transitions.
JavaScript
14
star
50

capper

Capture canvas animations.
JavaScript
12
star
51

Socket-Play

iPhone-controlled HTML5 game concept demo
JavaScript
12
star
52

Kinect-Keylight

Kinect version of @hakimel 's Keylight
C++
11
star
53

showme

show me the code (for an npm package)
JavaScript
11
star
54

workerify

Component for easy inline web worker
JavaScript
10
star
55

de-indent

remove extra indent from a block of code
JavaScript
10
star
56

new

Scaffold a new project.
JavaScript
8
star
57

Telekinesis

User gesture input simulation.
JavaScript
8
star
58

whipcream

Chai-style chaining sugar for webdriverjs
JavaScript
8
star
59

babel-plugin-transform-es2015-classes-simple

JavaScript
7
star
60

emitter-fsm

EventEmitter based finite state machine
JavaScript
6
star
61

rolldown-dce-repro

JavaScript
5
star
62

templates

Personal project scaffolding templates
JavaScript
5
star
63

choreo.js

Event-based flow control for interactive walkthroughs
JavaScript
4
star
64

gulp-jscoverage

JSCoverage instrumentation plugin for gulp
JavaScript
4
star
65

fancytext

Text with fancy transitions
JavaScript
4
star
66

roller

One-dimensional touch scroller with momentum and elastic pagination
JavaScript
4
star
67

test-cli-preset

JavaScript
4
star
68

gruntfile-yaml

write grunt config in yaml.
JavaScript
4
star
69

generator-extension

A Chrome extension generator
JavaScript
3
star
70

blaze-local-state

Local reactive state for Blaze templates
JavaScript
3
star
71

generator-dude

A personal Yeoman generator
JavaScript
3
star
72

tester

webhook tests.
JavaScript
2
star
73

gulp-component-updater

Gulp-friendly module to auto add/delete files in your component.json
JavaScript
2
star
74

grunt-component-add

Automatically add files to component.json
JavaScript
1
star