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

Optimisations no longer applied to _buildManifest.js when using SWC #31291

Closed
benschwarz opened this issue Nov 11, 2021 · 5 comments · Fixed by #31407 or #31639
Closed

Optimisations no longer applied to _buildManifest.js when using SWC #31291

benschwarz opened this issue Nov 11, 2021 · 5 comments · Fixed by #31407 or #31639
Assignees
Milestone

Comments

@benschwarz
Copy link
Contributor

What version of Next.js are you using?

12.0.4-canary.4

What version of Node.js are you using?

16.13.0

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

After enabling SWC I noticed that buildManfest.json's output grew significantly (20kb⇢80kb) because it is no longer using optimisations for chunk names, e.g: self.__BUILD_MANIFEST=function(e,s,a,t,c,o,n,i,r,g,l,b,d,u,p,f,h,m,k)

// With SWC off:
ls -lh .next/static/JdI1kHMMIQ4b_kwr2NZiG/_buildManifest.js

-rw-r--r--  1 benschwarz  staff    26K 11 Nov 18:58 .next/static/JdI1kHMMIQ4b_kwr2NZiG/_buildManifest.js


// With SWC on: 
ls -lh .next/static/dtDJS-Od0qktpqIrQBB_S/_buildManifest.js

-rw-r--r--  1 benschwarz  staff    80K 11 Nov 18:51 .next/static/dtDJS-Od0qktpqIrQBB_S/_buildManifest.js

Over the wire (with Gzip compression) the file size difference isn't anywhere near as dramatic (Repeated strings are of course optimised by Gzip, so they both end up around 6kb), but there may be an impact to JS parse & compile times, which could compromise main thread performance for sites with many pages.

Expected Behavior

Optimisations should be applied to _buildManifest.js to avoid a potential perf regression.

To Reproduce

  • Run rm -rf .next
  • Run next build
  • Observe size of .next/static/<generatedHash>/_buildManifest.js (small)
  • Run rm -rf .next
  • Turn on SWC using swcMinify: true in next.config.json
  • Run next build
  • Observe size of .next/static/<generatedHash>/_buildManifest.js (large)
@benschwarz benschwarz added the bug Issue was opened via the bug report template. label Nov 11, 2021
@timneutkens timneutkens added area: SWC Minify and removed bug Issue was opened via the bug report template. labels Nov 11, 2021
@timneutkens timneutkens added this to the 12.0.4 milestone Nov 11, 2021
@kdy1
Copy link
Member

kdy1 commented Nov 12, 2021

Okay, I found the cause. The inliner inlines strings because those are literal, which is ‘simple enough’.
I allowed it because the description of the google closure compiler said (in time of porting passes from it) they inline all strings because they focus on the gzipped size, but I can't find it currently.

I'll see if google closure compiler still inlines all string.

@benschwarz
Copy link
Contributor Author

heyo @kdy1, @timneutkens I tested again using 12.0.4 and I'm still seeing a _buildManifest.js request that's 80kb:

image

@kdy1
Copy link
Member

kdy1 commented Nov 17, 2021

I verified that it's not fixed, and I'll fix it soon.

kdy1 added a commit to swc-project/swc that referenced this issue Nov 20, 2021
swc_ecma_minifier:
 - Don't optimize `1 / t == -1 / 0` as `!1`.
 - Don't optimize `e === -1 / 0` as false.
 - Don't inline string literals in arguments, if it's used multiple time. (vercel/next.js#31291)
@kdy1 kdy1 mentioned this issue Nov 20, 2021
@kodiakhq kodiakhq bot closed this as completed in #31639 Nov 20, 2021
kodiakhq bot pushed a commit that referenced this issue Nov 20, 2021
The purpose of this PR is to apply

 - swc-project/swc#2779
   - Fixes #31291.
   - Not sure if it's fully fixed, but fixes some bugs related to #31391 

 - swc-project/swc#2818
   - Fixes #31627


I'll undraft this PR once swc-project/swc#2818 is fixed.
@benschwarz
Copy link
Contributor Author

Confirmed, LGTM on a new build with 12.0.5-canary.6 👍

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
The purpose of this PR is to apply

 - swc-project/swc#2779
   - Fixes vercel#31291.
   - Not sure if it's fully fixed, but fixes some bugs related to vercel#31391 

 - swc-project/swc#2818
   - Fixes vercel#31627


I'll undraft this PR once swc-project/swc#2818 is fixed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants