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

[DO NOT MERGE] chore(precompile): reduce the size of precompiled dependencies #58038

Closed
wants to merge 19 commits into from

Conversation

SukkaW
Copy link
Contributor

@SukkaW SukkaW commented Nov 4, 2023

The PR addresses https://twitter.com/hazae41/status/1720557445678858248.

Currently, The installation size of the next package is at 73.6 MiB. Among 53 MiB of them are precompiled dependencies.

The PR attempts to reduce that size by removing unused ones:

@ijjk ijjk added the type: next label Nov 4, 2023
@ijjk
Copy link
Member

ijjk commented Nov 4, 2023

Failing test suites

Commit: 7ddfe33

pnpm test test/integration/scss/test/scss-loader-handling.test.js

  • SCSS Support loader handling > production mode > Data Urls > should compile successfully
  • SCSS Support loader handling > production mode > Data Urls > should've emitted expected files
Expand output

● SCSS Support loader handling › production mode › Data Urls › should compile successfully

expect(received).toBe(expected) // Object.is equality

Expected: 0
Received: 1

  210 |         })
  211 |         // eslint-disable-next-line
> 212 |         expect(code).toBe(0)
      |                      ^
  213 |         // eslint-disable-next-line
  214 |         expect(stdout).toMatch(/Compiled successfully/)
  215 |       })

  at Object.toBe (integration/scss/test/scss-loader-handling.test.js:212:22)

● SCSS Support loader handling › production mode › Data Urls › should've emitted expected files

ENOENT: no such file or directory, scandir '/root/actions-runner/_work/next.js/next.js/test/integration/scss-fixtures/data-url/.next/static/css'

Read more about building and testing Next.js in contributing.md.

@ijjk
Copy link
Member

ijjk commented Nov 4, 2023

Stats from current PR

Default Build
General
vercel/next.js canary SukkaW/next.js remove-unused-precompile Change
buildDuration 12.9s 12.8s N/A
buildDurationCached 7.2s 6.2s N/A
nodeModulesSize 200 MB 198 MB N/A
nextStartRea..uration (ms) 428ms 421ms N/A
Client Bundles (main, webpack)
vercel/next.js canary SukkaW/next.js remove-unused-precompile Change
193.HASH.js gzip 181 B 182 B N/A
3f784ff6-HASH.js gzip 53.3 kB 53.3 kB
433-HASH.js gzip 28.6 kB 28.6 kB N/A
framework-HASH.js gzip 45.2 kB 45.2 kB
main-app-HASH.js gzip 240 B 242 B N/A
main-HASH.js gzip 31.7 kB 31.8 kB N/A
webpack-HASH.js gzip 1.7 kB 1.7 kB N/A
Overall change 98.5 kB 98.5 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary SukkaW/next.js remove-unused-precompile Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary SukkaW/next.js remove-unused-precompile Change
_app-HASH.js gzip 194 B 195 B N/A
_error-HASH.js gzip 183 B 181 B N/A
amp-HASH.js gzip 504 B 502 B N/A
css-HASH.js gzip 321 B 321 B
dynamic-HASH.js gzip 2.5 kB 2.5 kB N/A
edge-ssr-HASH.js gzip 255 B 253 B N/A
head-HASH.js gzip 350 B 349 B N/A
hooks-HASH.js gzip 369 B 369 B
image-HASH.js gzip 4.28 kB 4.28 kB N/A
index-HASH.js gzip 255 B 256 B N/A
link-HASH.js gzip 2.61 kB 2.61 kB
routerDirect..HASH.js gzip 312 B 311 B N/A
script-HASH.js gzip 385 B 383 B N/A
withRouter-HASH.js gzip 307 B 308 B N/A
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 3.4 kB 3.4 kB
Client Build Manifests
vercel/next.js canary SukkaW/next.js remove-unused-precompile Change
_buildManifest.js gzip 483 B 484 B N/A
Overall change 0 B 0 B
Rendered Page Sizes
vercel/next.js canary SukkaW/next.js remove-unused-precompile Change
index.html gzip 527 B 529 B N/A
link.html gzip 540 B 541 B N/A
withRouter.html gzip 523 B 524 B N/A
Overall change 0 B 0 B
Edge SSR bundle Size
vercel/next.js canary SukkaW/next.js remove-unused-precompile Change
edge-ssr.js gzip 93.8 kB 93.8 kB N/A
page.js gzip 147 kB 147 kB N/A
Overall change 0 B 0 B
Middleware size
vercel/next.js canary SukkaW/next.js remove-unused-precompile Change
middleware-b..fest.js gzip 625 B 622 B N/A
middleware-r..fest.js gzip 151 B 151 B
middleware.js gzip 37.4 kB 37.4 kB N/A
edge-runtime..pack.js gzip 1.92 kB 1.92 kB
Overall change 2.07 kB 2.07 kB
Next Runtimes
vercel/next.js canary SukkaW/next.js remove-unused-precompile Change
app-page-exp...dev.js gzip 169 kB 169 kB
app-page-exp..prod.js gzip 94.2 kB 94.2 kB
app-page-tur..prod.js gzip 94.9 kB 94.9 kB
app-page-tur..prod.js gzip 89.5 kB 89.5 kB
app-page.run...dev.js gzip 139 kB 139 kB
app-page.run..prod.js gzip 88.8 kB 88.8 kB
app-route-ex...dev.js gzip 24.1 kB 24.1 kB
app-route-ex..prod.js gzip 16.7 kB 16.7 kB
app-route-tu..prod.js gzip 16.7 kB 16.7 kB
app-route-tu..prod.js gzip 16.3 kB 16.3 kB
app-route.ru...dev.js gzip 23.5 kB 23.5 kB
app-route.ru..prod.js gzip 16.3 kB 16.3 kB
pages-api-tu..prod.js gzip 9.38 kB 9.38 kB
pages-api.ru...dev.js gzip 9.65 kB 9.65 kB
pages-api.ru..prod.js gzip 9.37 kB 9.37 kB
pages-turbo...prod.js gzip 21.9 kB 21.9 kB
pages.runtim...dev.js gzip 22.6 kB 22.6 kB
pages.runtim..prod.js gzip 21.9 kB 21.9 kB
server.runti..prod.js gzip 49.5 kB 49.5 kB
Overall change 932 kB 932 kB
Commit: 7ddfe33

@SukkaW SukkaW changed the title chore(precompile): remove find-cache-dir chore(precompile): remove unused precompiled dependencies Nov 4, 2023
@SukkaW SukkaW changed the title chore(precompile): remove unused precompiled dependencies chore(precompile): reduce the size of precompiled dependencies Nov 4, 2023
@SukkaW SukkaW marked this pull request as ready for review November 5, 2023 00:01
@feedthejim
Copy link
Contributor

What's the after size?

I think the watch pack one might be an oversight and we should re use the pre compiled one

@SukkaW
Copy link
Contributor Author

SukkaW commented Nov 5, 2023

What's the after size?

The final installation size reduction can be seen from the PR stats, nodeModulesSize. Currently, I've only reduced it from 175 MiB to 172 MiB.

I think the watch pack one might be an oversight and we should re-use the pre-compiled one

I can bring it up in the PR. This should help reduce the installation size further.


Edit: The pre-compiled watchpack is now back.

@SukkaW
Copy link
Contributor Author

SukkaW commented Jan 5, 2024

It seems that somehow sass-loader data url tests failed after the changes. I will look into this when I get time.

@styfle
Copy link
Member

styfle commented Jan 5, 2024

@SukkaW If its easier - you could split this up into a few PRs:

  • minify font
  • remove chalk
  • remove unused precompiled deps
  • compile watchpack

@SukkaW SukkaW marked this pull request as draft January 6, 2024 11:10
@SukkaW SukkaW changed the title chore(precompile): reduce the size of precompiled dependencies [DO NOT MERGE] chore(precompile): reduce the size of precompiled dependencies Jan 6, 2024
styfle pushed a commit that referenced this pull request Jan 8, 2024
Per @styfle suggestion, #58038 has been split into multiple PRs for
easier review.

- Enable minification of `@next/font`
- Currently, the `@next/font` is built separately (without minification)
and then copied to the `dist` folder of the Next.js.
styfle pushed a commit that referenced this pull request Jan 8, 2024
Per @styfle suggestion, #58038 has been split into multiple PRs for
easier review.

- Remove `find-cache-dir`
- The usage of `find-cache-dir` was removed **4 years ago**
(#7013) but the dist and the build
script were never removed.
- Remove `@segment/ajv-human-errors`
- The usage of `@segment/ajv-human-errors` was removed in
#56383 by me. Though the build
script was also removed in that PR, the dist never got removed.
styfle added a commit that referenced this pull request Jan 8, 2024
Per @styfle suggestion, #58038 has been split into multiple PRs for
easier review.

- Re-add precompile `watchpack`
- Next.js has stopped bundling the `watchpack` since
#50792. Currently, `watchpack` is
a direct dependency of Next.js. The PR adds the pre-compile back.

Co-authored-by: Steven <steven@ceriously.com>
ijjk added a commit that referenced this pull request Jan 8, 2024
Per @styfle suggestion, #58038 has been split into multiple PRs for
easier review.

- Remove `chalk` inside `@next/react-dev-overlay`
- `@next/react-dev-overlay` is bundled with Next.js. The usage of
`chalk` inside `@next/react-dev-overlay` was not removed in
#55992, thus the `chalk` is still
being shipped.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
@SukkaW
Copy link
Contributor Author

SukkaW commented Jan 13, 2024

All the subsequent PRs have been merged. The PR can be closed.

@SukkaW SukkaW closed this Jan 13, 2024
samcx added a commit that referenced this pull request Jan 19, 2024
The PR continues from #58038 aiming to reduce the installation size
further, and **improve performance in doing so**.

Most of `micromatch`'s APIs are essentially wrappers/alias of
`picomatch`, supplemented with additional features facilitated by a
transitive dependency `braces`. However, Next.js doesn't use those
"extra features". Switching from `micromatch` to `picomatch` can avoid
introducing the transitive dependency `braces`.

The PR also improves some globs' performance by hoisting.

- `micromatch.makeRe` is just an alias of `picomatch.makeRe`
-
https://github.com/micromatch/micromatch/blob/90dc0cd3e186b8ab4dd05bfc41e2b98f5067a49b/index.js#L387C30-L387C30
- `micromatch.isMatch(str, patterns, options)` equals
`picomatch(patterns, options)(str)`
-
https://github.com/micromatch/micromatch/blob/90dc0cd3e186b8ab4dd05bfc41e2b98f5067a49b/index.js#L123
- `micromatch.matcher` is just an alias of `picomatch`
-
https://github.com/micromatch/micromatch/blob/90dc0cd3e186b8ab4dd05bfc41e2b98f5067a49b/index.js#L104C1-L104C40

---------

Co-authored-by: Sam Ko <sam@vercel.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants