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-1143] Dev mode slow compilation #48748

Open
1 task done
jeengbe opened this issue Apr 23, 2023 · 555 comments
Open
1 task done

[NEXT-1143] Dev mode slow compilation #48748

jeengbe opened this issue Apr 23, 2023 · 555 comments
Assignees
Labels
linear: next Confirmed issue that is tracked by the Next.js team.

Comments

@jeengbe
Copy link

jeengbe commented Apr 23, 2023

⚠️ this original post has been edited by @timneutkens to reflect this comment ⚠️

Changes in the past week

I've been investigating this over the past week. Made a bunch of changes, some make a small impact, some make a large impact. Here's a list:

You can try them using npm install next@canary.

Help Investigate

In order to help me investigate this I'll ideally need an application that can be run, if you can't provide that (I understand if you can't) please provide the .next/trace file.

If possible follow these steps which would give me the best picture to investigate:

  • npm install next@canary (use the package manager you're using) -- We want to make sure you're using the very latest version of Next.js which includes the fixes mentioned earlier.
  • rm -rf .next
  • start development using the NEXT_CPU_PROF=1 and NEXT_TURBOPACK_TRACING=1 (regardless of if you're using Turbopack, it only affects when you do use Turbopack) environment variable. E.g.:
    • npm: NEXT_TURBOPACK_TRACING=1 NEXT_CPU_PROF=1 npm run dev
    • yarn: NEXT_TURBOPACK_TRACING=1 NEXT_CPU_PROF=1 yarn dev
    • pnpm: NEXT_TURBOPACK_TRACING=1 NEXT_CPU_PROF=1 pnpm dev
  • Wait a few seconds
  • Open a page that you're working on
  • Wait till it's fully loaded
  • Wait a few seconds
  • Make an edit to a file that holds a component that is on the page
  • Wait for the edit to apply
  • Wait a few seconds
  • Make another edit to the same file
  • Wait a few seconds
  • Exit the dev command (ctrl+c)
  • Upload the CPU traces put in the root of the application directory to https://gist.github.com
  • Upload the .next/trace file to https://gist.github.com -- Please don't run trace-to-tree yourself, as I use some other tools (e.g. Jaeger) that require the actual trace file.
  • If you're using Turbopack upload the .next/trace.log as well, if it's too large for GitHub gists you can upload it to Google Drive or Dropbox and share it through that.
  • Upload next.config.js (if you have one) to https://gist.github.com
  • Share it here

Known application-side slowdowns

To collect things I've seen before that cause slow compilation as this is often the root cause:

  • If you're on Windows, disable Windows Defender, it's a known cause of extreme slowdowns in filesystem access as it sends each file to an external endpoint before allowing to read/write
  • Filesystem slowness overall is what we've seen as the cause of problems, e.g. with Docker
  • react-icons, material icons, etc. Most of these libraries publish barrel files with a lot of re-exports. E.g. material-ui/icons ships 5500 module re-exports, which causes all of them to be compiled. You have to add modularizeImports to reduce it, here's an example: long compile times locally - along with "JavaScript heap out of memory" since upgrade to NextJS 13 #45529 (comment)
  • Custom postcss config, e.g. tailwindcss with a content setting that tries to read too many files (e.g. files not relevant for the application)

This and other slowdown reports are currently the top priority for our team. We'll continue optimizing Next.js with webpack where possible.
The Turbopack team is currently working on getting all Next.js integration tests passing when using Turbopack as we continue working towards stability of Turbopack.

Original post

Verify canary release

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

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
    Binaries:
      Node: 18.13.0
      npm: 8.19.3
      Yarn: 1.22.18
      pnpm: 7.30.5
    Relevant packages:
      next: 13.3.1
      eslint-config-next: 13.3.1
      react: 18.2.0
      react-dom: 18.2.0

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/DigitalerSchulhof/digitaler-schulhof

To Reproduce

Note that I have been unable to replicate this issue in a demo repository.

Describe the Bug

The issue is that Next.js is generally slow in dev mode. Navigating to new pages takes several seconds:

[next] ready - started server on 0.0.0.0:3000, url: http://localhost:3000
[next] info  - Loaded env from /home/jeengbe/dsh/digitaler-schulhof/.env
[next] warn  - You have enabled experimental feature (appDir) in next.config.js.
[next] warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
[next] info  - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
[next] event - compiled client and server successfully in 1574 ms (267 modules)
[next] wait  - compiling...
[next] event - compiled client and server successfully in 219 ms (267 modules)
[next] wait  - compiling /(schulhof)/Schulhof/page (client and server)...
[next] event - compiled client and server successfully in 3.6s (1364 modules)
[next] wait  - compiling /(schulhof)/Schulhof/(login)/Anmeldung/page (client and server)...
[next] event - compiled client and server successfully in 1920 ms (1411 modules)
[next] wait  - compiling /api/schulhof/auth/login/route (client and server)...
[next] event - compiled client and server successfully in 625 ms (1473 modules)
[next] wait  - compiling /(schulhof)/Schulhof/Nutzerkonto/page (client and server)...
[next] event - compiled client and server successfully in 1062 ms (1482 modules)
[next] wait  - compiling /(schulhof)/Schulhof/Nutzerkonto/Profil/page (client and server)...
[next] event - compiled client and server successfully in 1476 ms (1546 modules)
[next] wait  - compiling /(schulhof)/Schulhof/Nutzerkonto/Profil/Einstellungen/page (client and server)...
[next] event - compiled client and server successfully in 2.1s (1559 modules)

The only somewhat reasonable time would be 600ms for the API route /api/schulhof/auth/login/route, even though that is still quite a lot slower than what it should be given its size.

It also doesn't look right to compile ~1500 modules for each page, as most of them should be cached. The pages are not very different.

Even an empty API route takes several hundreds of ms. The following example contains solely type exports:

[next] wait  - compiling /api/schulhof/administration/persons/persons/settings/route (client and server)...
[next] event - compiled successfully in 303 ms (107 modules)

I am not exactly sure how to read trace trees, but what stands out is that there are (over multiple runs) several entry next-app-loader that take 2+ seconds to complete:

│  │  ├─ entry next-app-loader?name=app/(schulhof)/Schulhof/page&page=/(schulhof)/Schulhof/page&appPaths=/(schulhof)/Schulhof/page&pagePath=private-next-app-dir/(schulhof)/Schulhof/page.tsx&appDir=/home/jeengbe/dsh/digitaler-schulhof/app&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=/home/jeengbe/dsh/digitaler-schulhof&isDev=true&tsconfigPath=tsconfig.json&assetPrefix=&nextConfigOutput=! 1.9s

Find both dev and build traces here: https://gist.github.com/jeengbe/46220a09846de6535c188e78fb6da03e

Note that I have modified trace-to-tree.mjs to include event times for all events.

It also seems unusual that none of the modules have child traces.

Expected Behavior

Initial load and navigating should be substantially faster.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

From SyncLinear.com | NEXT-1143

@jeengbe jeengbe added the bug Issue was opened via the bug report template. label Apr 23, 2023
@joacub
Copy link

joacub commented Apr 24, 2023

same here, and in docker env is even worse, seems like is processing same files over and over without caching them.

@jinojacob15
Copy link

Same for me also dev env ,navigating to different pages via link component is pretty slow

@denu5
Copy link

denu5 commented Apr 25, 2023

+1 its same here, hitting the page first time seems fine but routing via links gets stuck

@joacub
Copy link

joacub commented Apr 25, 2023

last canary version has a better cold build times improvements, still slow like 2-5 seconds (in docker env) waiting but much better

the version im talking about is 13.3.2-canary.6

@denu5
Copy link

denu5 commented May 2, 2023

Hey, @jeengbe there have been some patch updates (13.3.1 -> 13.3.4) did it improve for you?

@jeengbe
Copy link
Author

jeengbe commented May 2, 2023

Hi @denu5,

unfortunately, I can't report any real performance changes since I opened this issue.

You might want to check out the above linked issue in the TypeScript repo though - might be related.

@joacub
Copy link

joacub commented May 2, 2023

As @jeengbe mention there is no performance improvement, there is also a lot of I/O I don’t know why, one request gets pretty much like 1gb-2gb of io. And it is very slow.

@jeengbe
Copy link
Author

jeengbe commented May 2, 2023

As @jeengbe mention there is no performance improvement, there is also a lot of I/O I don’t know why, one request gets pretty much like 1gb-2gb of io. And it is very slow.

Unfortunately, I can't confirm this for my case

image

@joacub
Copy link

joacub commented May 2, 2023

As @jeengbe mention there is no performance improvement, there is also a lot of I/O I don’t know why, one request gets pretty much like 1gb-2gb of io. And it is very slow.

Unfortunately, I can't confirm this for my case

image

That’s pretty good, in my case there is a lot of I/O, maybe is because I’m using material-ui but I think is too much even though.

@jeengbe
Copy link
Author

jeengbe commented May 2, 2023

As @jeengbe mention there is no performance improvement, there is also a lot of I/O I don’t know why, one request gets pretty much like 1gb-2gb of io. And it is very slow.

Unfortunately, I can't confirm this for my case
image

That’s pretty good, in my case there is a lot of I/O, maybe is because I’m using material-ui but I think is too much even though.

Possibly, it would align with what your trace shows: #48407 (comment)

@langfordG
Copy link

langfordG commented May 4, 2023

I see that slow route changes in dev mode are showing a '[Fast Refresh] rebuilding' message in the browser console. Sometimes it performs a full page reload when changing routes even if no files have been edited.

@timneutkens timneutkens added the linear: next Confirmed issue that is tracked by the Next.js team. label May 10, 2023
@timneutkens timneutkens changed the title Dev mode very slow navigation (Slow entry next-app-loader spans?) [NEXT-1143] Dev mode very slow navigation (Slow entry next-app-loader spans?) May 10, 2023
@AsathalMannan
Copy link

its slowing down the development..!

@vajajak
Copy link

vajajak commented May 21, 2023

Having the same issue here, in the Docker environment it's come to a point where it's almost unusable, and sometimes I even have to do a hard reload, after waiting too long for navigation. This is the case both with component from next/navigation, as with the router.push (useRouter hook imported from next/navigation). We're using Next.js 13.4.2.

@joacub
Copy link

joacub commented May 22, 2023

Having the same issue here, in the Docker environment it's come to a point where it's almost unusable, and sometimes I even have to do a hard reload, after waiting too long for navigation. This is the case both with component from next/navigation, as with the router.push (useRouter hook imported from next/navigation). We're using Next.js 13.4.2.

same here, it is almost not usable in dokcer enviorements, but also outside docker is very slow, something is not working nice. this is painfully slow.

@JoshApp
Copy link

JoshApp commented May 27, 2023

Yeah same for me. I used to remote develop inside our k8s cluster but dev --turbo is super slow inside a container and causes my health check endpoint to sigkill it regularly.

The whole app router is super slow when containerized in Dev mode.

It works perfectly fine when I run both on my local machine and connect it via reverse proxy. This way it's faster than the old setup (which was not significantly faster before) and takes advantage of preloading pages via next/link. I see inconsistencies in caching too where it's a mix of instant navigation or long builds (around 3.5k modules for some things) around 2-10 sec.

Also there is this weird thing happening that a page compiles just fine and then later it grinds to a halt being stuck in waiting for compiling forever until the pod is crashed.

@Rykuno
Copy link

Rykuno commented May 27, 2023

I love next, but this is a complete show stopper. Sometimes it takes 10+ seconds outside of docker for me on a Mac M2 to navigate one page.

This is insane.

@joacub
Copy link

joacub commented May 27, 2023

I love next, but this is a complete show stopper. Sometimes it takes 10+ seconds outside of docker for me on a Mac M2 to navigate one page.

This is insane.

Yep even more I get sometimes 50 seconds in a simple page, that’s because is also building other things related to that in pralllel I guess.

not even outside docker, i just make a test to work outside docker and timing is exactly the same no difference…. Is getting slower and slower

@joacub
Copy link

joacub commented May 27, 2023

Btw webpack lazy building cold is faster than turbopack 🙂 by far

@Rykuno
Copy link

Rykuno commented May 27, 2023

Btw webpack lazy building cold is faster than turbopack 🙂 by far

Yes! I'm surprised this is not more prevalent as an issue atm; unless turbo will somehow fix all of this in 13.5 and they're waiting to address it.

What configs do you have for the faster webpack builds? I've tried quite a bit and can't lower my built time by much. I need a temporary fix for this ASAP :(

@oalexdoda
Copy link

A month later no updates on this? Makes development on appDir absolutely impossible. @timneutkens ?

Linked a bunch of related issues on this:
#50332

@JunkyDeLuxe
Copy link

I confirm that next app dir on dev mode and dynamic routing are very very slow on docker now

@timneutkens
Copy link
Member

timneutkens commented Jun 6, 2023

Changes in the past week

I've been investigating this over the past week. Made a bunch of changes, some make a small impact, some make a large impact. Here's a list:

You can try them using npm install next@canary.

Help Investigate

In order to help me investigate this I'll ideally need an application that can be run, if you can't provide that (I understand if you can't) please provide the .next/trace file.

If possible follow these steps which would give me the best picture to investigate:

  • npm install next@canary (use the package manager you're using) -- We want to make sure you're using the very latest version of Next.js which includes the fixes mentioned earlier.
  • rm -rf .next
  • start development using the NEXT_CPU_PROF=1 environment variable. E.g.:
    • npm: NEXT_CPU_PROF=1 npm run dev
    • yarn: NEXT_CPU_PROF=1 yarn dev
    • pnpm: NEXT_CPU_PROF=1 pnpm dev
  • Wait a few seconds
  • Open a page that you're working on
  • Wait till it's fully loaded
  • Wait a few seconds
  • Make an edit to a file that holds a component that is on the page
  • Wait for the edit to apply
  • Wait a few seconds
  • Make another edit to the same file
  • Wait a few seconds
  • Exit the dev command (ctrl+c)
  • Upload the CPU traces put in the root of the application directory to https://gist.github.com
  • Upload the .next/trace file to https://gist.github.com -- Please don't run trace-to-tree yourself, as I use some other tools (e.g. Jaeger) that require the actual trace file.
  • Share it here

Known application-side slowdowns

To collect things I've seen before that cause slow compilation as this is often the root cause:

  • If you're on Windows, disable Windows Defender, it's a known cause of extreme slowdowns in filesystem access as it sends each file to an external endpoint before allowing to read/write
  • Filesystem slowness overall is what we've seen as the cause of problems, e.g. with Docker
  • react-icons, material icons, etc. Most of these libraries publish barrel files with a lot of re-exports. E.g. material-ui/icons ships 5500 module re-exports, which causes all of them to be compiled. You have to add modularizeImports to reduce it, here's an example: long compile times locally - along with "JavaScript heap out of memory" since upgrade to NextJS 13 #45529 (comment)
  • Custom postcss config, e.g. tailwindcss with a content setting that tries to read too many files (e.g. files not relevant for the application)

This and other slowdown reports are currently the top priority for our team. We'll continue optimizing Next.js with webpack where possible.
The Turbopack team is currently working on getting all Next.js integration tests passing when using Turbopack as we continue working towards stability of Turbopack.

@timneutkens timneutkens changed the title [NEXT-1143] Dev mode very slow navigation (Slow entry next-app-loader spans?) [NEXT-1143] Dev mode slow navigation Jun 6, 2023
@timneutkens timneutkens changed the title [NEXT-1143] Dev mode slow navigation [NEXT-1143] Dev mode slow compilation Jun 6, 2023
@timneutkens
Copy link
Member

Changed the initial post in this issue to reflect my reply above in order to ensure people see it as the first thing when opening the issue. I'm going to close the duplicate issues reporting similar slowdowns in favor of this one.

I'll need help from you all to ensure this thread doesn't spiral in "It is slow" comments that are not actionable when e.g. without traces / reproduction / further information. Thank you 🙏

@theogravity
Copy link

theogravity commented Sep 16, 2024

In our codebase, we used an icon.tsx file to show browser icons depending on the environment (dev or prod). After deleting this file, we experienced a performance boost in the dev environment. We could decrease the compile time from 3-10s to 1-2s per page load.

I'm not sure if this is already known or if this is the right place to post our finding. Feel free to close or move my comment.

Are you using react-icons? Even though the next.js team says it should be dealt with via an internal optimizePackageImports rule, I didn't see any improvements in loading times for it. Replacing react-icons with the icon library we used from it removed around 40s of initial startup time for us on next.js 15 RC.

There needs to be an article / perf guide around large barrel packages (packages that have a ton of exports in their main entrypoint) and advise that you do a direct import to the component if possible to help with these issues.

@theogravity
Copy link

theogravity commented Sep 16, 2024

I added the following to my scripts to troubleshoot (Next.js 15 RC):

{
  "scripts": {
    "build": "next build",
    "dev": "next dev",
    "prod": "next start",
    "dev:trace": "NEXT_TURBOPACK_TRACING=1 NEXT_CPU_PROF=1 next dev",
    "view-trace": "next internal turbo-trace-server ./.next/trace",
  },
}

Run dev:trace and let it load up to the page where you're trying to troubleshoot load times, then kill the server, then run view-trace to see the flamegraph.

One thing to note though that the flamegraph didn't feel anywhere near accurate (it was claiming that react-icons consumed only 10s, but it was in reality around 40s for us. However, the data was enough for us to investigate.

@T833357-SPARK
Copy link

next internal tur

I've fixed it and rerun a few times with bun next internal turbo-trace-server ./.next/trace and also bun next internal turbo-trace-server .next/trace

I still just get an infinite loading screen, WebSocket connection to 'ws://localhost:5747/' failed:

Figured it out though - I'm running in a Cloud9 instance. I tried running it locally and it works!

@T833357-SPARK
Copy link

Okay switching to --turbo has the compile times down to ~25 seconds, and faster hmr. Any way to further shave off time?

jotai-devtools is taking 1 second, mui is taking 1 second etc

@wang-h
Copy link

wang-h commented Sep 22, 2024

Big thanks to that bro whose answer got folded! I wasted a whole day on this. Ended up fixing it by switching from Webpack to Turbopack with this VSCode setup.

It finally works now!

What a rough day... Hope this helps someone else! Oh, and I’m using the new App Router, by the way!

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  "version": "0.2.0",
  "configurations": [  
    {
     "name": "Next.js: debug server-side",
      "type": "node-terminal",
      "request": "launch",
      "command": "npm run dev --turbo", //"npm run dev -- --turbo" any difference?
      "sourceMaps": true,
      "sourceMapPathOverrides": {
         "/turbopack/[project]/*": "${webRoot}/*"
      }
    },
    {
      "name": "Next.js: debug client-side",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
         "/turbopack/[project]/*": "${webRoot}/*"
      }

    }, 
    {
      "name": "Next.js: debug full stack",
      "type": "node-terminal",
      "request": "launch",
      "command": "npm run dev",
      "skipFiles": ["<node_internals>/**"],
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "/turbopack/[project]/*": "${webRoot}/*"
      },
      "serverReadyAction": {
        "action": "debugWithChrome",
        "killOnServerStop": true,
        "pattern": "- Local:.+(https?://.+)",
        "uriFormat": "%s",
        "webRoot": "${workspaceFolder}"
      }
    }
  ]
}

@kavinvalli
Copy link

kavinvalli commented Sep 24, 2024

Hey @timneutkens, https://github.com/helicone/helicone - we've been experiencing extremely slow dev compile times recently. Here's the trace: https://gist.github.com/kavinvalli/58946c70ed5d95265c13ac126356a8f1

Would be very helpful if you could take a look, since I'm not able to make out anything specific from pnpm next internal turbo-trace-server

image

@maxiedaniels
Copy link

Hey! Wondering if someone could look at my cpuprofile and trace? Link: https://gist.github.com/maxiedaniels/a949a901ce60bab38bee883e4c65c980

My pages take 5-10 seconds to load (from a refresh) in dev mode, but not in production. I've gone over all the normal causes and haven't found a solution. Thanks for the help!!

@olafurns7
Copy link

Hi,

Using next 14.2.13 in turborepo, not using turbopack.

We're trying to utilize a generic page to handle CMS based routing, so we have:

app/src/[locale]/[[...slug]]/page.tsx

This has grown unsustainable as right now, even after attempts to trim down imports, we have around 4000 modules being logged during HMR, causing HMR to take ~2+ seconds.

.next/trace
cpu trace

We've tried all sorts of attempts to dynamically import components/files, but most of our code is not "client" components, so using lazy or next/dynamic really doesn't have any real effect on our structure.

We will probably resort to creating some hard coded level one navigation paths, but this is pretty strange behaviour and this issue was not this prominent in the pages router using a similar architechture.

@mfrachet
Copy link

mfrachet commented Oct 7, 2024

@timneutkens sorry for the wild ping. If you still have time to check other projects with slow compilation, here's the actual situation for us:

For context

  • We use turbo (latest) and pnpm (8.7) for the monorepo
  • We use turbopack with the --turbo flag on next dev
  • We compiled all the barrel TS files on which we have control (the workspaces basically) to limit the time spent by TS
  • We use optimizePackageImports in the nextjs config to optimize tree shaking (our package graph looks good)
  • In this Google Drive folder, you'll find a video showing the issue, the trace file and the trace.log files

Questions

  • Is there a way we can read in details where the compiler is spending time? For instance "trying to compile lib XYZ and took X seconds" ? So that we can try to isolate the problem ahead of time?
  • What else could we try? (Detecting barrel files from external dependencies seems to be a bit annoying if done manually)

Thanks for your help and good luck with dealing with those types of issues (we know it's a pain) 🙏🏻 .

@atsixian
Copy link

atsixian commented Oct 8, 2024

Hey @timneutkens, NEXT_CPU_PROF=1 yarn dev gives this error every time. Do u know the possible causes?
Next.js version: 15.0.0-canary.179.

Cannot generate CPU profiling: Error [ERR_INSPECTOR_COMMAND]: Inspector error -32000: No recording profiles found

@lauri865
Copy link

lauri865 commented Oct 10, 2024

For us, --turbo is actually slower to compile initially than not using --turbo on next@15.0.0-canary.182:

Without --turbo

✓ Ready in 1882ms
✓ Compiled /home in 2s (3590 modules)

With --turbo

✓ Ready in 769ms
✓ Compiled /home in 7.3s

Unfortunately HMR is a whole different story though, and --turbo makes that part a whole lot faster.

It would also help if the root route would be precompiled inline with next dev, because what's the use of having the server start up in 750ms, if the longest action has to be sequentially and manually triggered by the developer? The amount of time I'm losing to this every day is abysmal. Instead, if the root route would be prewarmed, it would make things go along much faster, evern for all sequential routes, as the main layout would be precompiled.

For the time being, we've hacked the instrumentation hook to trigger a fetch, which helps, but it boggles my mind that this is not the default behavior of a framework that claims to be all about developer experience.

instrumentation.ts

export const register =
  process.env.NODE_ENV === "development"
    ? () => {
        console.log("PRELOADING ROOT ROUTE");
        fetch(`http://localhost:${process.env.PORT}`);
      }
    : undefined;

@gsusI
Copy link

gsusI commented Oct 11, 2024

"If you're on Windows, disable Windows Defender, it's a known cause of extreme slowdowns in filesystem access as it sends each file to an external endpoint before allowing to read/write"

Installing malware might help, but I'm sure we want to focus on solutions that don't pose security risks to our systems.

@woodytang
Copy link

ubuntu 24.04 i7 6700, very slow, cpu usage is high when compiling

@feedthejim
Copy link
Contributor

Hi everyone, if you're affected by dev perf issues, I'd like to share that Turbopack Dev is now stable in Next.js 15.

Please try it out today: https://nextjs.org/blog/next-15 and let us know how it's going.

@oalexdoda
Copy link

oalexdoda commented Oct 22, 2024

image

Hey team, any clue how to debug this? All was well last night, tried to upgrade to Next 15, didn't work, rolled back, and now it's stuck on compiling no matter what. Tried to delete .next, node_modules, etc.

It's just getting stuck on "compiling" no matter the page. No VPN or anything else.

Update: Seems to only happen when using turbo. Could it be a @sentry issue? Here's what shows when running the app without Turbo (which works):

image

@blackhaj
Copy link

Hey @timneutkens

Here is our CPU Trace our Next trace and our Next config

We have spent a lot of time removing barrel files from dependencies we control but page transitions are still very slow for us locally and we would love any pointers you have

@maciesielka
Copy link

maciesielka commented Oct 25, 2024

Congrats on Turbopack Dev stability! We're still having problems with the dev experience, particularly with cold starts in both Webpack and Turbopack, so any pointers you have would be great!

I've followed the steps mentioned in this thread for both Webpack and Turbopack for comparison and have provided the info below:

  • webpack trace: gist
  • turbopack trace-turbopack: google drive (wasn't a format understood by Gist and is fairly large)
  • next config: gist
  • CPU trace: couldn't find this exactly, if someone could point me more specifically at it I'll provide it

Some other notes:

  • we are fully migrated to App Router
  • this is all tested on the just-launched Next 15 after following the migration guide

@oalexdoda
Copy link

Just wanted to drop this here, not sure if it helps - but it seems like most of the slowdown is due to RSC. Here's an example of a page getting loaded that seems to take 2-6 seconds multiple times. Not sure why it's doing that, but the overall route compiles in 3 seconds, followed by a long wait around RSC.

image

@mischnic
Copy link
Contributor

mischnic commented Oct 28, 2024

@maciesielka It's taking a minute to process a single CSS file with some JS tool. Do you have a Tailwind/PostCSS config? Please share that as well then. (E.g. With Tailwind it's easy to accidentally include all of node_modules in its class scanning).

Bildschirmfoto 2024-10-25 um 22 41 31

@timneutkens
Copy link
Member

@oalexdoda the time shown for GET logs includes execution of your own code, the logs Compiled in are only Webpack/Turbopack processing.

@blackhaj can you try Turbopack first?

@maciesielka looks like it's one of these, given nearly all time is spent on Node.js execution:

CleanShot 2024-10-28 at 08 41 58@2x

Edit: Seems Niklas already looked at the trace too 😄

@maciesielka
Copy link

maciesielka commented Oct 28, 2024

@mischnic @timneutkens Thanks for your help! I've updated the gist from the previous post to include our tailwind and postcss configs, but I'll take a closer look given your notes above.

@maciesielka
Copy link

maciesielka commented Oct 28, 2024

@mischnic @timneutkens Thanks for your help! I've updated the gist from the previous post to include our tailwind and postcss configs, but I'll take a closer look given your notes above.

This investigation was fruitful. Ignoring codgen-generated files that have no need for Tailwind from our tailwind.config.js made a massive improvement. 🚀

@maxiedaniels
Copy link

@timneutkens @mischnic Hey guys! Just wanted to point out my debug files again - Link: https://gist.github.com/maxiedaniels/a949a901ce60bab38bee883e4c65c980

My pages take 5-10 seconds to load (from a refresh) in dev mode, but not in production. I've gone over all the normal causes and haven't found a solution. Thanks for the help!!

@timneutkens
Copy link
Member

@maxiedaniels now that Turbopack is stable for development I'd recommend trying that first, the trace for Turbopack will also be more complete than the webpack one.

@maxiedaniels
Copy link

@maxiedaniels now that Turbopack is stable for development I'd recommend trying that first, the trace for Turbopack will also be more complete than the webpack one.

Can I use the stable Turbopack on Next.js 14 or would I have to upgrade to 15?

@timneutkens
Copy link
Member

Experimental on 14, stable on 15 🙂

@mo-rally-dev
Copy link

+1 on moving to Turbopack.

We recently bumped our Next version to 15, enabled Turbopack, and it changed everything! Next 14 helped a bit with the local dev experience but it was still painful. Upgrading to Next 15 with Turbopack finally resolved all of our pain points.

The upgrade was well worth the time, and I highly recommend it to anyone dealing with slow dev mode!

@dazuaz
Copy link

dazuaz commented Oct 31, 2024

I experienced significant performance issues in my Next.js project, specifically when importing a non-treeshaking library at the top level of an action.ts file. After some testing, the only solution that worked for me was to:

Delete the import of the non-treeshakable library from the top-level action.ts file.
Move that library and related code closer to where it was actually needed in the project.
After making these adjustments, I noticed a substantial improvement in performance and more reasonable build and load times.

@umashankar-pardhi-amla

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear: next Confirmed issue that is tracked by the Next.js team.
Projects
None yet
Development

No branches or pull requests