engine icon indicating copy to clipboard operation
engine copied to clipboard

Replaces Terser/Babel. Improves Build Time

Open marklundin opened this issue 1 year ago • 5 comments

This PR replaces Babel + Terser with SWC which improves the build time of each target.

The same ES5 targets are used for UMD build outputs.

With Terser/Babel ~ 1m40s

created build/playcanvas.js in 9.9s
created build/playcanvas in 6.2s
created build/playcanvas.mjs in 1.3s
created build/playcanvas.dbg.js in 9.8s
created build/playcanvas.dbg in 6s
created build/playcanvas.dbg.mjs in 1.8s
created build/playcanvas.prf.js in 9.4s
created build/playcanvas.prf in 6s
created build/playcanvas.prf.mjs in 1.2s
created build/playcanvas.min.js in 7.5s
created build/playcanvas.min.mjs in 6.4s

With SWC ~ 51s

created build/playcanvas.js in 3.6s
created build/playcanvas in 2.6s
created build/playcanvas.mjs in 1.3s
created build/playcanvas.dbg.js in 3.8s
created build/playcanvas.dbg in 2.6s
created build/playcanvas.dbg.mjs in 1.6s
created build/playcanvas.prf.js in 3.2s
created build/playcanvas.prf in 2.6s
created build/playcanvas.prf.mjs in 1.2s
created build/playcanvas.min.js in 1.9s
created build/playcanvas.min.mjs in 1.4s

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

marklundin avatar Sep 06 '24 15:09 marklundin

Any change to sizes?

LeXXik avatar Sep 06 '24 16:09 LeXXik

Also is there a difference in ECMA compliance, if there is a difference between ES5 versio s, and what it results in?

Maksims avatar Sep 06 '24 17:09 Maksims

It has the same targets for both UMD and ES builds, so should match current outputs.

I need to adjust some settings to get the build size back in line though, so consider this draft for now.

On Fri, 6 Sep 2024 at 18:15, mrmaxm @.***> wrote:

Also is there a difference in ECMA compliance, if there is a difference between ES5 versio s, and what it results in?

— Reply to this email directly, view it on GitHub https://github.com/playcanvas/engine/pull/6920#issuecomment-2334493431, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADJFLFPULMRTOP2IBLJDHTZVHPLDAVCNFSM6AAAAABNY3P7G2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZUGQ4TGNBTGE . You are receiving this because you authored the thread.Message ID: @.***>

marklundin avatar Sep 06 '24 17:09 marklundin

If it is not possible to bring the build size to what terser is capable of, then we can consider to use this for a debug build, as it is usually the one that takes the most of the time during development and its size is of less importance.

LeXXik avatar Sep 09 '24 09:09 LeXXik

Below are the file sizes. Will continue investigating

Build Output SWC Babel/Terser
playcanvas.d.ts 1.7MiB 1.7MiB
playcanvas.dbg.js 16MiB 18MiB
playcanvas.dbg.mjs 13MiB 16MiB
playcanvas.js 2.8MiB 2.9MiB
playcanvas.min.js 1.6MiB 1.7MiB
playcanvas.min.mjs 1.6MiB 1.6MiB
playcanvas.mjs 2.7MiB 2.5MiB
playcanvas.prf.js 2.8MiB 2.9MiB
playcanvas.prf.mjs 2.7MiB 2.5MiB

marklundin avatar Sep 13 '24 14:09 marklundin

The wins from this look extremely compelling. I'd be supportive of switching.

willeastcott avatar Dec 23 '24 23:12 willeastcott

Comparison of Existing Build System vs SWC

File Existing Gzip Size Existing Build Time SWC Gzip Size SWC Build Time
playcanvas.dbg.js 4.0MiB 10.7s 3.9MiB 4.9s
playcanvas.dbg.mjs 3.2MiB 2.5s 3.2MiB 2.2s
playcanvas.js 588KiB 10.6s 555KiB 3.4s
playcanvas.min.js 431KiB 7.0s 412KiB 1.9s
playcanvas.min.mjs 416KiB 6.5s 419KiB 1.8s
playcanvas.mjs 536KiB 1.4s 551KiB 1.4s
playcanvas.prf.js 589KiB 8.8s 556KiB 5.1s
playcanvas.prf.mjs 537KiB 1.4s 552KiB 2.0s

Observations

  • Build Times: SWC achieves faster build times across all most types
  • Gzip Sizes: SWC gzip sizes are generally comparable or slightly smaller, except for playcanvas.min.mjs and playcanvas.mjs.

marklundin avatar Dec 24 '24 13:12 marklundin

I've stumbled upon this ticket at rollup: https://github.com/rollup/rollup/pull/5073

It seems they use SWC since version 4.x. Which means, we are already using it indirectly. Is the speedup coming from dropping Babel+Terser?

LeXXik avatar Jan 08 '25 22:01 LeXXik

I've stumbled upon this ticket at rollup: rollup/rollup#5073

It seems they use SWC since version 4.x. Which means, we are already using it indirectly. Is the speedup coming from dropping Babel+Terser?

This is just for internally parsing the AST in Rollup. It still relies on external plugins such as @rollup/plugin-babel for transpiling/lowering/minifying the final output. Previously we were using terser for minifying and babel for transpiling which are both JS implementations. SWC is Rust, so it's a lot faster and handles both transpiling and minifying.

marklundin avatar Jan 09 '25 09:01 marklundin