Skip to content

Commit

Permalink
Use swc for runtime bundling (#55842)
Browse files Browse the repository at this point in the history
This swaps the existing minifier for the Next.js runtime bundling from [terser](https://github.com/terser/terser) over to [swc](https://swc.rs/docs/configuration/minification). This small change has slightly decreased development file sizes, and dramatically decreased the time it takes to bundle the runtime. The results below were ran once on my MacBook Pro (M1 Pro).

## Compilation Speed

About 3 times faster

- `next_bundle_pages_dev`: improved from 7.28s to 1.85s.
- `next_bundle_pages_turbo`: improved from 7.28s to 1.85s.
- `next_bundle_pages_prod`: improved from 7.28s to 1.93s.
- `next_bundle_server`: improved from 7.28s to 2.68s.
- `next_bundle_app_turbo`: improved from 8.09s to 2.89s.
- `next_bundle_app_turbo_experimental`: improved from 7.74s to 2.77s.
- `next_bundle_app_prod`: improved from 7.86s to 2.77s.
- `next_bundle_app_dev`: improved from 9.41s to 2.86s.
- `next_bundle_app_prod_experimental`: improved from 8.01s to 3.12s.
- `next_bundle_app_dev_experimental`: improved from 9.11s to 3.58s.
- `next_bundle`: improved from 9.50s to 3.69s.

## File Sizes

About the same, small improvements in development bundle sizes

```shell
# Using terser
692K    packages/next/dist/compiled/next-server/app-page-experimental.runtime.dev.js
460K    packages/next/dist/compiled/next-server/app-page-experimental.runtime.prod.js
460K    packages/next/dist/compiled/next-server/app-page-turbo-experimental.runtime.prod.js
436K    packages/next/dist/compiled/next-server/app-page-turbo.runtime.prod.js
672K    packages/next/dist/compiled/next-server/app-page.runtime.dev.js
436K    packages/next/dist/compiled/next-server/app-page.runtime.prod.js
 68K    packages/next/dist/compiled/next-server/app-route-experimental.runtime.dev.js
 48K    packages/next/dist/compiled/next-server/app-route-experimental.runtime.prod.js
 48K    packages/next/dist/compiled/next-server/app-route-turbo-experimental.runtime.prod.js
 48K    packages/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js
 68K    packages/next/dist/compiled/next-server/app-route.runtime.dev.js
 48K    packages/next/dist/compiled/next-server/app-route.runtime.prod.js
 28K    packages/next/dist/compiled/next-server/pages-api-turbo.runtime.prod.js
 28K    packages/next/dist/compiled/next-server/pages-api.runtime.dev.js
 28K    packages/next/dist/compiled/next-server/pages-api.runtime.prod.js
 64K    packages/next/dist/compiled/next-server/pages-turbo.runtime.prod.js
 68K    packages/next/dist/compiled/next-server/pages.runtime.dev.js
 64K    packages/next/dist/compiled/next-server/pages.runtime.prod.js
204K    packages/next/dist/compiled/next-server/server.runtime.prod.js

# Using swc
684K    packages/next/dist/compiled/next-server/app-page-experimental.runtime.dev.js
460K    packages/next/dist/compiled/next-server/app-page-experimental.runtime.prod.js
460K    packages/next/dist/compiled/next-server/app-page-turbo-experimental.runtime.prod.js
436K    packages/next/dist/compiled/next-server/app-page-turbo.runtime.prod.js
660K    packages/next/dist/compiled/next-server/app-page.runtime.dev.js
436K    packages/next/dist/compiled/next-server/app-page.runtime.prod.js
 68K    packages/next/dist/compiled/next-server/app-route-experimental.runtime.dev.js
 48K    packages/next/dist/compiled/next-server/app-route-experimental.runtime.prod.js
 48K    packages/next/dist/compiled/next-server/app-route-turbo-experimental.runtime.prod.js
 48K    packages/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js
 68K    packages/next/dist/compiled/next-server/app-route.runtime.dev.js
 48K    packages/next/dist/compiled/next-server/app-route.runtime.prod.js
 28K    packages/next/dist/compiled/next-server/pages-api-turbo.runtime.prod.js
 28K    packages/next/dist/compiled/next-server/pages-api.runtime.dev.js
 28K    packages/next/dist/compiled/next-server/pages-api.runtime.prod.js
 64K    packages/next/dist/compiled/next-server/pages-turbo.runtime.prod.js
 68K    packages/next/dist/compiled/next-server/pages.runtime.dev.js
 64K    packages/next/dist/compiled/next-server/pages.runtime.prod.js
204K    packages/next/dist/compiled/next-server/server.runtime.prod.js
```
  • Loading branch information
wyattjoh committed Sep 22, 2023
1 parent b0aeccc commit ce42a99
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/next/webpack.config.js
Expand Up @@ -135,19 +135,18 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => {
optimization: {
moduleIds: 'named',
minimize: true,
// splitChunks: {
// chunks: 'all',
// },
concatenateModules: true,
minimizer: [
new TerserPlugin({
extractComments: false,
minify: TerserPlugin.swcMinify,
terserOptions: {
format: {
comments: false,
},
compress: {
passes: 2,
dead_code: true,
// Zero means no limit.
passes: 0,
},
format: {
preamble: '',
},
},
}),
Expand Down

0 comments on commit ce42a99

Please sign in to comment.