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

Migrate from Terser and Babel to SWC #6920

Merged
merged 29 commits into from
Jan 9, 2025
Merged

Migrate from Terser and Babel to SWC #6920

merged 29 commits into from
Jan 9, 2025

Conversation

marklundin
Copy link
Member

@marklundin marklundin commented Sep 6, 2024

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.

@LeXXik
Copy link
Contributor

LeXXik commented Sep 6, 2024

Any change to sizes?

@Maksims
Copy link
Collaborator

Maksims commented Sep 6, 2024

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

@marklundin
Copy link
Member Author

marklundin commented Sep 6, 2024 via email

@LeXXik
Copy link
Contributor

LeXXik commented Sep 9, 2024

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.

@marklundin
Copy link
Member Author

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

package.json Outdated Show resolved Hide resolved
@willeastcott
Copy link
Contributor

willeastcott commented Dec 23, 2024

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

- Added "peer": true to several existing dependencies to indicate peer dependencies.
- Introduced new modules: jackspeak (v3.4.3) and package-json-from-dist (v1.0.1) with their respective details.
- Added path-scurry (v1.11.1) and its dependency lru-cache (v10.4.3) with funding information.

These changes enhance dependency management and ensure compatibility with peer dependencies.
- Eliminated the babel-parser dependency from the ESLint configuration file.
- Updated the parser options to ensure compatibility with the existing setup.

These changes streamline the ESLint configuration and reduce unnecessary dependencies.
- Changed the import name of the SWC plugin from 'swc' to 'swcPlugin' for clarity.
- Updated all instances in the buildTarget function to use the new import name.

These changes improve code readability and maintainability.
- Removed several unused Babel-related dependencies from package.json and package-lock.json to streamline the project.
- Updated the package-lock.json to reflect the removal of these dependencies and added optional flags where applicable.
- Enhanced dependency management by ensuring that only necessary modules are retained, improving overall project maintainability.
… rollup-spaces-to-tabs.mjs

- Deleted the rollup-script-target.mjs file, streamlining the build process.
- Updated swcOptions to ensure comments are preserved in the output when not minifying.
- Clarified documentation in rollup-spaces-to-tabs.mjs regarding the plugin's functionality.

These changes enhance code maintainability and improve the clarity of the build configuration.
…s for Rollup. See vitejs/vite#15532

- Added optional dependencies for various Rollup packages, including support for multiple platforms (Linux, Darwin, FreeBSD, Windows).
- Updated package-lock.json to reflect the addition of these optional dependencies and their respective versions.
- This change enhances cross-platform compatibility and ensures that the build process can leverage the appropriate Rollup binaries as needed.
…lated dependencies

- Upgraded @swc/core to version 1.10.1 and updated its dependencies across various platforms.
- Removed the optional dependency for @rollup/rollup-linux-x64-gnu.
- Updated @swc/types to version 0.1.17 for improved compatibility.
- These changes enhance the project's build capabilities and ensure better support for the latest SWC features.
@marklundin
Copy link
Member Author

marklundin commented Dec 24, 2024

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.

@willeastcott willeastcott changed the title Replaces Terser/Babel. Improves Build Time Migrate from Terser and Babel to SWC Dec 26, 2024
eslint.config.mjs Outdated Show resolved Hide resolved
- Removed the parserOptions.requireConfigFile setting from the ESLint configuration.
…, and include several new devDependencies

- Removed the deprecated @napi-rs/canvas dependency from package.json and package-lock.json.
- Added canvas version 3.0.1 to both files.
- Introduced multiple new development dependencies, enhancing the project's capabilities and ensuring compatibility with the latest features.
@LeXXik
Copy link
Contributor

LeXXik commented Jan 8, 2025

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?

@marklundin
Copy link
Member Author

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.

tsconfig.json Outdated Show resolved Hide resolved
marklundin and others added 3 commits January 9, 2025 12:58
- Upgraded the @swc/core dependency from version 1.10.1 to 1.10.4 in both package.json and package-lock.json to ensure compatibility with the latest features and improvements.
- Eliminated the skipLibCheck option from the TypeScript configuration to enforce stricter type checking and improve code quality.
@marklundin marklundin merged commit d60ba07 into main Jan 9, 2025
8 checks passed
@marklundin marklundin deleted the feat-swc-compiler branch January 9, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants