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

[NEXT-1172] Performance of the build has detoriated after 13.3.0 #49593

Closed
1 task done
jonime opened this issue May 10, 2023 · 5 comments · Fixed by #49937 or #50194
Closed
1 task done

[NEXT-1172] Performance of the build has detoriated after 13.3.0 #49593

jonime opened this issue May 10, 2023 · 5 comments · Fixed by #49937 or #50194
Assignees
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.

Comments

@jonime
Copy link

jonime commented May 10, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
Binaries:
  Node: 18.15.0
  npm: 9.5.0
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.4.2-canary.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 4.9.5

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://github.com/jonime/next-build-multithreading-issue

To Reproduce

  • npm run build

Describe the Bug

Build performance has deteriorated after updating to 13.3.0 or later. The build process doesn't seem to use cores properly because CPU usage is less than 100%.

next@13.2.4
npm run build  26.38s user 9.03s system 270% cpu 13.068 total

next@13.3.0
npm run build  27.16s user 8.40s system 94% cpu 37.733 total

next@13.4.1
npm run build  26.03s user 8.69s system 89% cpu 38.780 total

next@13.4.2-canary.4
npm run build  23.02s user 7.39s system 88% cpu 34.267 total

next@13.4.3-canary.0
npm run build  28.97s user 8.36s system 89% cpu 41.489 total

Expected Behavior

Build should be faster

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1172

@jonime jonime added the bug Issue was opened via the bug report template. label May 10, 2023
@timneutkens timneutkens added the linear: next Confirmed issue that is tracked by the Next.js team. label May 17, 2023
@timneutkens timneutkens changed the title Performance of the build has detoriated after 13.3.0 [NEXT-1172] Performance of the build has detoriated after 13.3.0 May 17, 2023
@kodiakhq kodiakhq bot closed this as completed in #49937 May 17, 2023
kodiakhq bot pushed a commit that referenced this issue May 17, 2023
It seems the build workers count calc change that was made in #47823 caused a regression in performance as we aren't utilizing as many workers as we previously did so this moves that change behind an experimental flag while additional tweaking is investigated. 

x-ref: #47823
Fixes: #49593
@ijjk
Copy link
Member

ijjk commented May 17, 2023

Hi, this has been updated in v13.4.3-canary.2 of Next.js, please update and give it a try!

@jonime
Copy link
Author

jonime commented May 18, 2023

Sadly, this fix didn't seem to solve the issue we are having.

I was able to pinpoint an exact canary version where this issue started v13.2.5-canary.25...v13.2.5-canary.26

next@13.2.5-canary.25
npm run build  26.54s user 7.86s system 271% cpu 12.676 total

next@13.2.5-canary.26
npm run build  23.06s user 8.27s system 90% cpu 34.771 total

next@13.4.3-canary.2
npm run build  25.17s user 7.86s system 90% cpu 36.379 total

Before increasing the value of the experimental.cpus had a direct impact on build time and CPU usage:

next@13.2.5-canary.25

experimental.cpus = 1
npm run build  17.94s user 6.76s system 81% cpu 30.138 total

experimental.cpus = 2
npm run build  14.22s user 6.18s system 123% cpu 16.548 total

experimental.cpus = 4
npm run build  17.02s user 6.91s system 200% cpu 11.949 total

experimental.cpus = 8
npm run build  21.36s user 8.28s system 301% cpu 9.818 total

experimental.cpus = 16
npm run build  27.34s user 8.63s system 350% cpu 10.252 total

With the latest canary version, it has a really small impact on build time or CPU usage:

next@13.4.3-canary.2

experimental.cpus = 1
npm run build  13.79s user 6.47s system 75% cpu 26.904 total

experimental.cpus = 8
npm run build  14.40s user 6.62s system 78% cpu 26.864 total

experimental.cpus = 16
npm run build  15.24s user 6.61s system 81% cpu 26.790 total

I got those numbers using time npm run build in https://github.com/jonime/next-build-multithreading-issue with Macbook Pro M1 max.

This issue causes build time to increase quite much in our real-world project when building it (1 minute build time to 6 minutes):

built 1796 pages

next@13.4.3-canary.2
npm run build:next  179.64s user 17.96s system 52% cpu 6:18.62 total

next@13.1.6
npm run build:next  123.74s user 13.37s system 197% cpu 1:09.59 total

@timneutkens
Copy link
Member

We'll investigate further 👍

ijjk added a commit that referenced this issue May 23, 2023
This removes the `computeWorkerKey` from our static workers as this
doesn't work in practice as efficiently as we hoped since a single page
can have thousands of paths to render which won't be distributed to
separate workers if the same worker key is returned.

Fixes: #49593

**Before**

![before](https://github.com/vercel/next.js/assets/22380829/da1e0a03-8b15-42a6-a2ac-6e4ff29c350d)


**After**

![after](https://github.com/vercel/next.js/assets/22380829/b27354f6-bcdb-4cad-888c-7d6b143e0ee2)
@hucki
Copy link

hucki commented May 30, 2023

For us the problem seems to be mitigated since using version 13.3.4 (including #50194).

The build times are not as low as we are experiencing in our current 12.3 deployments but compared to 13.3.3 and before the build times dropped significantly.

Thanks for the fix!

hydRAnger pushed a commit to hydRAnger/next.js that referenced this issue Jun 12, 2023
It seems the build workers count calc change that was made in vercel#47823 caused a regression in performance as we aren't utilizing as many workers as we previously did so this moves that change behind an experimental flag while additional tweaking is investigated. 

x-ref: vercel#47823
Fixes: vercel#49593
hydRAnger pushed a commit to hydRAnger/next.js that referenced this issue Jun 12, 2023
This removes the `computeWorkerKey` from our static workers as this
doesn't work in practice as efficiently as we hoped since a single page
can have thousands of paths to render which won't be distributed to
separate workers if the same worker key is returned.

Fixes: vercel#49593

**Before**

![before](https://github.com/vercel/next.js/assets/22380829/da1e0a03-8b15-42a6-a2ac-6e4ff29c350d)


**After**

![after](https://github.com/vercel/next.js/assets/22380829/b27354f6-bcdb-4cad-888c-7d6b143e0ee2)
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.
Projects
None yet
4 participants