-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Comments
same here, and in docker env is even worse, seems like is processing same files over and over without caching them. |
Same for me also dev env ,navigating to different pages via link component is pretty slow |
+1 its same here, hitting the page first time seems fine but routing via links gets stuck |
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 |
Hey, @jeengbe there have been some patch updates (13.3.1 -> 13.3.4) did it improve for you? |
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. |
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 |
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) |
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. |
entry next-app-loader
spans?)entry next-app-loader
spans?)
its slowing down the development..! |
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. |
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. |
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 |
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 :( |
A month later no updates on this? Makes development on appDir absolutely impossible. @timneutkens ? Linked a bunch of related issues on this: |
I confirm that next app dir on dev mode and dynamic routing are very very slow on docker now |
Changes in the past weekI'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 Help InvestigateIn 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 If possible follow these steps which would give me the best picture to investigate:
Known application-side slowdownsTo collect things I've seen before that cause slow compilation as this is often the root cause:
This and other slowdown reports are currently the top priority for our team. We'll continue optimizing Next.js with webpack where possible. |
entry next-app-loader
spans?)
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 🙏 |
Can I use the stable Turbopack on Next.js 14 or would I have to upgrade to 15? |
Experimental on 14, stable on 15 🙂 |
+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! |
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. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I’ve been testing some of the optimizations mentioned and would like to share my observations: Compilation Improvement for Large Applications (#50792): I tested this on a mid-sized app (approximately 1,000 modules in development mode) and saw about a 15% improvement in compilation speed. While not as dramatic as the reported 50% for the Vercel website, the improvement was noticeable and appreciated. This small but impactful change has made a difference in environments where favicon.ico is intentionally omitted. Previously, this triggered unnecessary fallback behavior in local development, which is now bypassed efficiently. Thank you for addressing this! Following the steps provided, I captured .next/trace and CPU profile data for a small-to-medium app. I noticed the following: The point about barrel files from libraries like Material-UI resonated with my experience. For example, after switching to modularizeImports for a Material-UI-heavy project, I observed a noticeable reduction in memory usage and compile times. Thanks for reiterating this tip! |
I wanted to share my experience in case it is helpful for others - as I had to 'learn' some hard lessons - and hopefully this can save others the same pain. =) TL;DR: Do not use next/dynamic on barrel file libraries (it defeats the optimization and creates unnecessary big module counts) and any server-side only packages - consider using My situation: Fairly large production NextJS 14.2.15 App Router application. Experiencing major recompile times during development. Had my main workflow page - lots of components - taking 180-225s to recompile and load up. Terribly slow. Other pages - that I would consider normal size - roughly 20-40s compile times... Outcome: My big page now has initial compile time of 35s and recompile times on save < 3s. All other pages have initial compile time of <5s and HMR triggers our very fast on small changes.... What fix MY issue (and might help you - I hope!):
|
I'm still facing the same issue even after updating to "next": "14.2.12." This issue was first reported back in 2023, and it's frustrating that it still persists after a year. While caching is working fine, I'm not sure what the focus is on—if the development environment isn't stable, what’s the point of using Next for development? Can anyone assist me with this? 31 sec for compiling , also the page is also not refreshing |
This comment has been minimized.
This comment has been minimized.
We recently upgraded to next 15 and now use turbopack. We still have compile times ranging from 0.3 to 10s for first compiles on machine. Inside docker we have compile times of up to 300s with turobpack (compare to 10s with webpack). So this issue vercel/turborepo#4748 also certainly still is not resolved. However turbopack is also not a solution on machine. |
I'm observing long delay between when a page is compiled and when it starts rendering: [28.11.2024 18:09.14.728] [LOG] ○ Compiling / ...
[28.11.2024 18:09.33.759] [LOG] Source path: /.../src/app/globals.css
-- LOG START tailwindcss
[28.11.2024 18:09.33.760] [LOG] Setting up new context...
[28.11.2024 18:09.33.964] [LOG] Finding changed files: 24.909ms
[28.11.2024 18:09.34.799] [LOG] Reading changed files: 824.456ms
[28.11.2024 18:09.34.805] [LOG] Sorting candidates: 6.378ms
[28.11.2024 18:09.34.975] [LOG] Generate rules: 176.403ms
[28.11.2024 18:09.34.979] [LOG] Build stylesheet: 3.324ms
[28.11.2024 18:09.34.998] [LOG] Potential classes: 4195
[28.11.2024 18:09.34.998] [LOG] Active contexts: 1
[28.11.2024 18:09.35.139] [LOG] JIT TOTAL: 1.456s
-- LOG END tailwindcss
[28.11.2024 18:09.42.720] [LOG] ✓ Compiled / in 28.6s (2589 modules)
[28.11.2024 18:10.17.731] [LOG] Render RootLayout
...
GET / 200 in 72884ms No idea how it can take 72sec. How can I find out what's taking so long? Some details:
|
For everyone right now facing this issue, the culprit for me was tailwind css. I found this sollution on stackoverflow: https://stackoverflow.com/a/70742247 My hot reaload times went from 10-30 seconds to < 1 second! What it does is it seperates the tailwind compiler from the next js and runs as a seperate process. it basically creates a new file output.css which you can import in your global.css @tailwind base; and add it to the input.css magically all the slow dev problems I've had are gone! |
@kepman |
You need to create the file.. "dev": "concurrently "next dev --turbo" "npx tailwindcss -i ./tailwind/input.css -o ./tailwind/output.css --watch"" |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@timneutkens you can find my gist here and my trace.log here. pnpx next@canary internal turbo-trace-server ./.next/trace.log
pnpx next@canary internal turbo-trace-server .next/trace.log both don't seem to work for me, both commands in terminal finish with ⚠ Turbopack trace server started. View trace at https://turbo-trace-viewer.vercel.app/
Trace file opened
39% read (128/325 MB, 99 MB/s)
78% read (256/325 MB, 114 MB/s)
98% read (320/325 MB, 118 MB/s)
Initial read completed (325 MB, 2.7s) but in the developer console of my browser I see WebSocket connection to 'ws://localhost:5747/' failed:
t.createOrJoinSocket so I think I'm currently unable to review the logs myself. I am using TCP 127.0.0.1:5747 0.0.0.0:0 LISTENING |
@timneutkens CPU Profile and trace here Thought it was |
Hi @timneutkens - we have an issue with cold start compilation times consistently taking 8-13+ seconds for our app. Incremental compilation takes far quicker (in the double digit milliseconds). Was going to raise a separate issue but felt this issue was better to report via. We've generated the trace file and explored it via the trace viewer, however we can't drill in further so hoping you could provide some insight.
For us seems like the module graph and client references phases are the culprits. Appreciate any help you can provide. |
Hey @timneutkens! We're also seeing cold start & edit issues causing major development slowdown. After going through this thread several times and trying to debug myself, would love some tips on what might be causing this. Attached is a minimal (all instrumentation removed)
|
I tried Nextjs 15 with React 19. I have to say it is extremely slow and annoying to work with. It is taking more than 10 seconds to reflect a change. Not a very convenient experience honestly. This is slowing down development speed and productivity. Thinking about switching to Nextjs 14. PS: I removed |
My previous comment #48748 (comment) suggested to provide a systematic documentation on the problems and possible solutions. @timneutkens It's unfortunate to see that this issue is not getting any attention anymore. I think the issue is two fold:
|
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:
pages
andapp
and you're only working onapp
it will no longer compile the runtime forpages
. Note: this shifts the compilation of the runtime to when you first open a pageYou 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
NEXT_CPU_PROF=1
andNEXT_TURBOPACK_TRACING=1
(regardless of if you're using Turbopack, it only affects when you do use Turbopack) environment variable. E.g.:NEXT_TURBOPACK_TRACING=1 NEXT_CPU_PROF=1 npm run dev
NEXT_TURBOPACK_TRACING=1 NEXT_CPU_PROF=1 yarn dev
NEXT_TURBOPACK_TRACING=1 NEXT_CPU_PROF=1 pnpm dev
ctrl+c
).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..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.next.config.js
(if you have one) to https://gist.git.luolix.topKnown application-side slowdowns
To collect things I've seen before that cause slow compilation as this is often the root cause:
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 addmodularizeImports
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)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
Provide environment information
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:
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:
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: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
The text was updated successfully, but these errors were encountered: