wmr icon indicating copy to clipboard operation
wmr copied to clipboard

[DRAFT] Code-split bundled WMR for performance

Open developit opened this issue 5 years ago â€ĸ 5 comments

Currently we generate a single 1.5mb wmr.cjs file. This is really nice for distribution, but it does mean that anyone running wmr pays the full cost of parsing and compiling all that JS, even though roughly half of it is used depending on whether you're running wmr or wmr build.

I've tested out a few configurations, and this is what I came up with: basically it generates a couple more files (3 or 4) so that "prod bundling" and "http2" are handled in 1.1mb and 160kb commonjs modules that are conditionally loaded the first time they are used. In the case of running wmr (watch mode), neither are loaded.

I'm on the fence about whether this is the right thing to do. From a performance standpoint it will probably be a faster startup, but it complicates delivery (in a way that maybe only I care about? lol) đŸ“Ļ

developit avatar Jul 13 '20 02:07 developit

Size Change: -289 kB (43%) 🎉

Total Size: 660 kB

Filename Size Change
wmr.cjs 376 kB -289 kB (76%) 🏆
â„šī¸ View Unchanged
Filename Size Change
demo/dist/assets/style.********.css 266 B 0 B
demo/dist/assets/style.module.********.css 53 B 0 B
demo/dist/chunks/index.********.js 294 B 0 B
demo/dist/index.********.js 5.95 kB 0 B
demo/dist/index.html 403 B 0 B
wmr.bundler.cjs 194 kB 0 B
wmr.http2.cjs 57.5 kB 0 B
wmr.watch.cjs 25.5 kB 0 B

compressed-size-action

github-actions[bot] avatar Jul 13 '20 02:07 github-actions[bot]

Is is possible to have both? I forget, does rollup support an array for outputs? (looking at their docs for 20s seems like no?) Wondering if we could output twice: once with inlineDynamicImports: false and once with inlineDynamicImports: true.

andrewiggins avatar Jul 13 '20 19:07 andrewiggins

Could do, yeah. But then which would we ship?

developit avatar Jul 13 '20 22:07 developit

I'm fine with either approach. The startup time seems to be more desirable, as that is likely the way it will be used by the majority of users.

marvinhagemeister avatar Jul 14 '20 11:07 marvinhagemeister

I might try to get this splitted out so that it's just the main wmr.cjs and wmr.build.cjs, which is loaded for the build command or wmr --prebuild. At 25kb there's not much reason to split out watch and same goes for the http2 stuff I think.

developit avatar Jul 15 '20 03:07 developit