Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further optimize esbuild binary output #36453

Closed
samouri opened this issue Oct 21, 2021 · 3 comments
Closed

Further optimize esbuild binary output #36453

samouri opened this issue Oct 21, 2021 · 3 comments
Assignees

Comments

@samouri
Copy link
Member

samouri commented Oct 21, 2021

summary
As of the time of this writing, the closure compiled output is smaller than that created by esbuild.

v0.mjs brotli v0.mjs uncompressed
closure compiler on main 60.82 212.68
esbuild on main 63.25 232.76

There are four low hanging fruit that I believe can close the gap:

  1. Closure is smarter about DCEing unused static functions from classes. esbuild does not do this due to a nuance with correctness. One simple solution is to rewrite our biggest offender, Services to be all toplevel exported functions instead of static class functions. This shaves <0.5kb br, 5kb uncompressed> from esbuild output.
  2. DCE of polyfills: pjs-promises in particular is DCEd by closure but not by esbuild. This is another ~0.8kb br compressed.
  3. Closure is very aggressive about inlining properties specified with @enum as opposed to forcing a property access. This is often smaller output as well. Unsure of size impact here.
  4. The src/config code is in every single binary, but only needs to be in Runtime.
@samouri samouri changed the title Optimize ESbuild output Optimize esbuild output Oct 21, 2021
@samouri samouri self-assigned this Oct 21, 2021
@samouri samouri changed the title Optimize esbuild output Optimize esbuild binariy output Oct 21, 2021
@samouri
Copy link
Member Author

samouri commented Oct 26, 2021

updates

--

With (1) and (2) alone the diff between CC and esbuild is now 1.7%

@samouri samouri changed the title Optimize esbuild binariy output Optimize esbuild binary output Oct 26, 2021
@samouri
Copy link
Member Author

samouri commented Nov 5, 2021

update

@samouri samouri changed the title Optimize esbuild binary output Further optimize esbuild binary output Nov 22, 2021
@samouri
Copy link
Member Author

samouri commented Nov 30, 2021

updates
Due to dropping the CE polyfill, all values have dropped by ~1.3kb 🎉 . This means that our "esbuild on main" branch is now smaller than Closure output was as of a month ago (60.66 vs. 60.93).

The table below shows current state, along with a few potential optimizations we could toggle on.

Each individually is an incredibly mild improvement and bears some risk.
Therefore I plan on test them out after the transition is complete.

v0.mjs brotli v0.mjs uncompressed
closure compiler on main 59.46 208.01
esbuild on main 60.66 218.51
esbuild w/unsafe 60.46 218.01
esbuild w/unsafe + pure_getters 60.21 217.16
esbuild w/unsafe + pure_getters + remove nth_identifier 60.12 217.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant