Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Chapter 94 of the unending quest to minimise bundle size. I noticed while looking at the minified output of a @TehShrike project that a lot of variable names end up being two characters rather than just one. That's because a) a typical Svelte component declares several variables/functions (the constructor itself, any fragment functions, local CSS encapsulation helper, etc), and b) Rollup and webpack combine all the top-level variables and functions into a shared scope (known as scope hoisting).
In theory, scope hoisting makes minification easier, because module A can refer to module B's exports directly, rather than as (unmangleable) properties of a module object. In practice, however, it can mean that you have so many top-level variables that Uglify runs out of single-character names, and has to use two-character names.
Wrapping the generated module in an IIFE means there's only one top-level declaration. Empirically, this results in slightly smaller minified code (which means lower parse costs). Unminified code ends up slightly more readable, because Rollup doesn't keep renaming functions to avoid conflicts (
create_main_fragment
,create_main_fragment$1
,create_main_fragment$2
etc). Those benefits ought to increase further if we move things out of thetemplate
object and remove the IIFE that surrounds it, per #756.Gzipped code is actually very slightly larger, however, with the code I've tried so far. Not sure how much weight to place on this, since gzip is such a mysterious beast. So it probably warrants a bit more testing before we decide if this is a desirable change.