next.js: [NEXT-1143] Dev mode slow compilation
⚠️ 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:
- Affects all applications
- https://github.com/vercel/next.js/pull/50745
- https://github.com/vercel/next.js/pull/50795 – If you don’t have a favicon.ico
- https://github.com/vercel/next.js/pull/50379 – If you have both
pagesandappand you’re only working onappit will no longer compile the runtime forpages. Note: this shifts the compilation of the runtime to when you first open a page
- Might not affect your app
- https://github.com/vercel/next.js/pull/50792 – This one I’ve only been able to reproduce on the Vercel website in development, it might make your compilation a lot faster (i.e. 50% faster for Vercel’s website) but in most cases it likely won’t affect your application.
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=1andNEXT_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
- npm:
- 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/tracefile 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.logas 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 addmodularizeImportsto reduce it, here’s an example: https://github.com/vercel/next.js/issues/45529#issuecomment-1531912811- Custom postcss config, e.g. tailwindcss with a
contentsetting 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 248
- Comments: 598 (169 by maintainers)
Commits related to this issue
- Remove edge functions tracking in dev server (#51122) ## What? While looking at the CPU profile of booting up Vercel's site I noticed that we call `getPageStaticInfo` a lot. Looking into this mor... — committed to vercel/next.js by timneutkens 3 years ago
- Add default modularizeImports that breaks up lucide-react, mui/icons-material, lodash, react-bootstrap (#50900) ## What? Adds a default modularizeImports that ensures `lucide-react`, `@mui/icons-mat... — committed to vercel/next.js by timneutkens 3 years ago
- Add default modularizeImports for antd / ant-design/icons / ahooks (#52031) Follow up to #50900. Based on https://github.com/vercel/next.js/issues/48748#issuecomment-1608783867 — committed to vercel/next.js by timneutkens 3 years ago
- chore(package): remove prettier check for slow formatting in next.js 13 - see: https://github.com/vercel/next.js/issues/48748 — committed to JengYoung/DDU_DU_DDU_DU by JengYoung 3 years ago
- Add `mui-core` to the default `optimizePackageImports` list (#55554) Feedback from https://github.com/vercel/next.js/issues/48748#issuecomment-1714292279. As per my testing, an App Router route of ... — committed to vercel/next.js by shuding 3 years ago
- chore: update next to see if increase dev speed (https://github.com/vercel/next.js/issues/48748#issuecomment-1556137809) — committed to iaurg/42-transcendence by iaurg 3 years ago
- feat/82: match history (#84) * feat: create base page for listing * fix: update node to 20 to fix nextjs hot reload * refactor: remove not used import * feat: match history components * w... — committed to iaurg/42-transcendence by iaurg 3 years ago
- Implement Turbopack trace server bindings (#65410) ## What? Implements support for running the Turbopack trace server, which is the websocket server that powers https://turbo-trace-viewer.vercel.... — committed to vercel/next.js by timneutkens 3 years ago
- Implement Turbopack trace server bindings (#65410) Implements support for running the Turbopack trace server, which is the websocket server that powers https://turbo-trace-viewer.vercel.app/ when usi... — committed to vercel/next.js by timneutkens 3 years ago
- Implement Turbopack trace server bindings (#65410) Implements support for running the Turbopack trace server, which is the websocket server that powers https://turbo-trace-viewer.vercel.app/ when usi... — committed to vercel/next.js by timneutkens 3 years ago
- Implement Turbopack trace server bindings (#65410) Implements support for running the Turbopack trace server, which is the websocket server that powers https://turbo-trace-viewer.vercel.app/ when usi... — committed to vercel/next.js by timneutkens 3 years ago
I will try to keep it brief as I could write / talk about this for a few hours 😄
A few years ago, before Vite had much adoption, we started seeing larger and larger web applications built on top of Next.js, including enterprise adoption on teams of 100+ developers. These codebases grow to tens of thousands of custom components, and on top of that importing packages from npm. In short: even though webpack, which we were using at the time (and still are if you don’t opt-in to Turbopack), is actually quite fast, it wasn’t fast enough for these ever increasing codebase sizes.
We also saw a trend of general applications become much more compilation heavy, largely caused by the rise of component libraries / icon libraries. Today, as you can see in this thread, it’s not uncommon for a super small application to end up compiling 20K modules or more because of published design systems and icon libraries being use.
The problem we saw is that even if we optimize webpack to the maximum there is still a cap on the amount of modules it can process because if you have 20.000 modules even spending 1 millisecond per module ends up being 20 seconds if you can’t parallelize the processing.
On top of that we’re not just running 1 webpack compiler, we were running 3. One for server, one for browser, one for edge runtime. This causes complexity because these separate compilers have to coordinate as there is no shared module graph.
Around the same time we also started exploring React Server Components, App Router, and overall how we’d want Next.js development to look in 5-10 years from now. One of the main topics of that was around code that can go from server->client->server->client, in short, if you’re familiar, Server Actions, and specifically that Server Actions can return JSX that holds additional client components. In order to make that work we found that having a single unified module graph that can hold both server, client, and edge code in the same bundler/compiler would be very beneficial. This is something that bundlers like Parcel had been exploring for quite a while.
At the time we evaluated all existing solutions and found that each of them has trade-offs, I’m not going to “throw others under the bus” as these trade-offs all make sense, they just didn’t make sense for a framework like Next.js and especially Next.js in the future (this was around ~2020 if I remember correctly).
Overall let’s talk a bit about the goals, some of these benefit you as a user, some benefit maintenance:
Faster HMR
Faster initial compile of a route
Minimal changes
next/fontthat have to be added.Scales to the largest TS/JS codebases
Persistent caching
Production builds that closely match development
Production optimizations that go beyond current bundlers
Less flakiness in the compiler / compile times
(Later) Next.js aware bundler tooling
(Later) Next.js / RSC aware bundling optimizations
Full observability for maintainers
Personally I’m happy to see Vite is doing well in the ecosystem. They’re also taking learnings from other bundlers. If you look at the recent work they’ve been doing with Rolldown you’ll see quite some similarities, it’s going back to bundling instead of “unbundling” for compiler performance for example.
Guess writing this up still took more time than I wanted to spend on it, but I hope it’s helpful!
TLDR: other bundlers are great, but they don’t fit well for a framework like Next.js, we want to bring these improvements to existing users, in order to do that we had to build a new bundler that takes learnings from a whole lot of different approaches that have been tried before.
Same for me also dev env ,navigating to different pages via link component is pretty slow
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.
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:
pagesandappand you’re only working onappit 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/tracefile.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 .nextNEXT_CPU_PROF=1environment variable. E.g.:NEXT_CPU_PROF=1 npm run devNEXT_CPU_PROF=1 yarn devNEXT_CPU_PROF=1 pnpm devctrl+c).next/tracefile 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.Known 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 addmodularizeImportsto reduce it, here’s an example: https://github.com/vercel/next.js/issues/45529#issuecomment-1531912811contentsetting 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.
I’m realizing that all this hype about next 13 is more commercial than real.
700x faster than X 156156156X better than Y But in practice, even a hello world takes that long to load?
I read in some answer that it is intentional to render “on-deman” on the first visit of the page to save resources, CPU, etc… But I don’t need that, there are resources left… There’s no point in saying “✓ Ready in 3s” if when opening the link it starts to really work… ○ Compiling /page… ✓ Compiled /page in 7.4s (1061 modules) ✓ Compiled in 775ms (381 modules) ○ Compiling /api/auth/[…nextauth]/route … ✓ Compiled /api/auth/[…nextauth]/route in 5.8s (1043 modules) ✓ Compiled /(auth)/login/page in 991ms (1100 modules)
Isn’t there a way to create an approach like: when ready, start crawling and rendering the next links and pages close to the current one instead of standing still and doing nothing?
Or as a last resort, render everything! Once ready, let me start working and keep updating only what was changed…
This is so frustrating!
Hey all, I wanted to share an update on this after spending most of this week investigating slowdowns together with @shuding.
For Vercel’s application which we used for profiling the following list of changes had a big impact, reducing compile times for a page without caching (intentionally deleting the cache each run) by 53.48%. We’re still working on further investigation and improvements as there is still more room to improve. Would appreciate if you’re able to upgrade to
next@canary(npm install next@canary) and run the steps to provide the CPU profile and trace again (steps here: https://github.com/vercel/next.js/issues/48748#issue-1680013792). That would allow us to confirm the changes have the intended impact on your application too, as we’ve been using Vercel’s application to confirm these improvements.Both App and Pages
@mui/icons-material@mui/materialdate-fnslodashlodash-esramdareact-bootstrap. When you use those significantly less modules will be compiled.statandreadFilebetween them. Improved performance on Vercel’s app by 300-400ms on initial compilesfs.readFilebeing faster for the file. So more efficient disk space usage.What I did before out of office:
apporpagesto the first request for either, this allows us to avoid compiling thepagesruntime whenappis only usedApp Only
A: https://github.com/vercel/next.js/pull/51924app. For Vercel’s app this improved cold compilation by 20% to 30%What I did before out of office:
apporpagesto the first request for either, this allows us to avoid compiling thepagesruntime whenappis only usedappby 95.2%. @shuding improved this even further in #51924its slowing down the development…!
+1 its same here, hitting the page first time seems fine but routing via links gets stuck
A month later no updates on this? Makes development on appDir absolutely impossible. @timneutkens ?
Linked a bunch of related issues on this: https://github.com/vercel/next.js/issues/50332
The problem with this issue (and any issues around memory usage) is that for the majority of people posting are all running into different problems. If you look at my earlier replies you’ll notice some patterns: misconfiguration of TailwindCSS, additional libraries added (i.e. Datadog) that instrument Node.js internals and then severely slow down the application, and many other examples of this every application is somewhat unique problem.
In some cases it’s ~over 10K modules being imported, for example when people used material-ui/icons which publishes an incredible 11000 modules as a single re-exports file, many similar icon libraries do that as well.
As part of that we’ve implemented some very specific optimizations for these particular libraries that can expand them at the risk that this requires the library to be side-effect free, if it has side-effects those will not run as only the used exports are included.
This 11000 modules case was already a problem in Next.js 12 / Pages Router. The main reason you’re seeing that case take ~twice as long in that particular case with App Router is that in App Router all node_modules are bundled on the server-side too. You might be wondering why we would even make that change, it was working fine in Pages Router right? Well, there’s a few reasons:
next start, boot on Vercel, boot on AWS Lambda, boot on Edge Functions, and found a big improvement to cold boots when bundling as much as possible, if you’re curious as to why it’s faster, well, eachrequiresynchronous and has to read the filesystem in Node.js. When it’s a single file you can skip quite some overhead.If you search back in this issue you’ll find some of my earlier updates around the optimizations we’ve done in 13.4.8/9/10 (and later on too) that reduced most reports of slowdowns without a clear reason, i.e. people that had no large module graph. The reason those ran into this slowdown is that webpack has a heuristic for turning file watchers into directory watchers internally, as the amount of entrypoints / modules in the module graph increased webpack (watchpack to be precise) started converting thousands of file watchers to directory watchers, which is a slow process. This is what I ended up optimization.
There were a few other cases where the amount of file reads could be reduced which is what we’ve also implemented as part of those patch releases and some other optimizations.
Since landing those optimizations things have been mostly back to normal in terms of the CPU profiles that were provided, where the majority of complaints are coming from applications that:
In looking into some of these there is another part to keep in mind that is being reported as “slowness”, which is that when you edit Server Components we have to fetch the server to re-render the entire page to get the new results, currently that means that when you edit Server Components it also triggers your data fetching, which can often look like “Next.js is slow”. For this case we’re exploring if we can automatically reuse the last data fetching result during re-render after Server Components change, that would remove data from the critical path for Server Components changes.
Our goal is indeed for Turbopack to be the default in Next.js so that the majority of applications benefits from faster development and production builds, we are running the entire Next.js test suite against the Turbopack implementation every day currently, we’ll be sharing a website soon where you can track the progress, currently at 87% of the development test suite and this number is increasing every day.
We still have some ideas / learnings from Turbopack that could be somewhat backported to webpack like leveraging the optimized CSS parser based on LightningCSS and a few changes to how entries are generated, but I’m not expecting that to feel sufficient when you’ve used Turbopack.
Overall keep the CPU profiles coming, it’s helpful to see them regardless to see if there’s other parts of Next.js / Webpack / Turbopack to optimize. @bfowle I’m expecting it to be a combination of something, I wasn’t able to reproduce the not writing both profiles but will ask someone on our team to take a look into it 🙏
If we look at video editing software as an analogy, I really love how Apple Final Cut Pro does it:
Before this, in video editing software, you had to manually click “render” to render all clips, or try and play that clip which would trigger a render just on that clip (this is similar to next dev right now)
The apple final cut pro method should be translated to the next compiler:
I believe this would make
next deva lot faster/nicer to work with, but I’m not sure how complicated this would be to implement.Last solution guys: Switch to Linux (windows sux).
Hey everyone, as a bunch of people have asked about the trace viewer I’ve worked on publishing the tooling we use so that you can have a look yourself using
next@canary.Just so that everyone is on the same page this tooling is intentionally very low level, it’s the tools we use to investigate slowdowns.
Specifically you can run these files:
.next/traceDefault tracing that instruments webpack in development and production build.next/trace.logOnly written when usingNEXT_TURBOPACK_TRACING=1and is specific to TurbopackYou can run it using this command on
next@canary:It will link to https://turbo-trace-viewer.vercel.app/ where you can view the trace. Few notes on navigation:
in ordermeans in the order of which they occuredby valuemeans left-heavy, ordering the slowest spans from left to right – Useful for finding which files are slow to process and such.Only one trace file can be viewed at a time currently.
The trace viewer is still a work in progress, but already quite useful to us.
I was out of office the past two weeks so sorry that there wasn’t an update in the meantime. We’ve made a few improvements while I was out:
NEXT_CPU_PROF=1environment variable to write CPU profiles to diskI’m going to have a look into the traces tomorrow 👍
@timneutkens Can we get a bit more systematic here and maybe also collect more general instructions? I know the detailed debugs are helpful for individual users and also for next to understand what is going on, but it will not allow for a good dx out of the box. Many recommendations you need to find by browsing through very large GitHub issues and lots of it is outdated.
In addition to that, there still seem to be a more fundamental issues, because I keep reading here about initial compile times of 10s and even reloads that exceed seconds after a very fair share of optimization. I can only compare that to other frameworks I worked with and given the very high hardware demands (e.g. 64GB RAM and M1 Max are not sufficient to be really fast), this is frustrating.
So what I gathered so far:
package.jsonMaybe there is a chance you add something to the next documentation about this?
And then back to my problem:
Upgrading to
13.4.8yields major performance improvements for one of my largest Next.js apps. ~700 pages, 10k TS modules, 100+ contributors.Some pages were previously taking 40-90 seconds on
13.4.7, compiling in ~5-7 seconds on 13.4.8.Thanks all who worked on this! ▲
It’s almost impossible to use
devmode in nextjs development due to incredibly slow compilation in dev mode that heavily affects the system too. Most of the timesnextgoes out of memory, and the system freezes for a long time.We are not using
devmode anymore for development. our solution for now is:This is the
most critical problemfor nextjs and I really hope there is a solution for it anytime soon.I thought this would go without saying after my latest updates to this issue but apparently it does not so I’ll repeat it again:
If you’re on a version of Next.js before 13.4.8 please upgrade to
next@latest, as earlier comments that were posted have shown that holds a massive improvement for many applications.If you are still running into issues please follow the steps provided in the initial post, I’ve been keeping those steps up to date and I can’t make them any simpler, all you have to do is run your application with an environment variable and share the trace and cpu profiles: https://github.com/vercel/next.js/issues/48748
I’ll reiterate some known slowdowns which we can’t optimize much:
On the other hand there’s applications that upgraded, got a performance boost, and then found “It’s still slow”, specifically when opening a page for the first time / navigating to other pages. We’ve been looking at those CPU profiles too, generally I’ve replied saying I didn’t see anything large to optimize for those, generally those are larger applications, like 10K-modules or more. Those cases are exactly why we started building Turbopack. Before Next.js 13 was released there were reports of people building these larger applications (we realized later a bunch of these got bitten by material-ui/icons and such). Vercel’s application is similar to those larger applications, it requires a lot of files to be compiled, especially on the dashboard. So we started building Turbopack as a way to get to much faster “time to opening a page”. We’re still making progress on Turbopack and I’m excited about the early results there. Ultimately these larger applications need the new infrastructure in order to scale further, and that’s why we’ve invested so much time and energy into building Turbopack. That is not just about development speed but also scaling
next build.Solution: Version: 13.1 next.config:
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.
On the one hand, it’s incredibly nice of you to help everyone figure out their situation, including all this very challenging debugging.
On the other hand, if devs had to go through this process with every dependency we use, you can imagine how intractable that would be. Quite simply, no one expects to choose a framework and then run into these kinds of problems.
From my perspective, the app router and all of the compilation changes that go with it should have been released as a beta, because they were clearly not ready for production. Early adopters could have tried it out, and worked with you to iron out all these issues. But doing a general release was really unfair to all of your serious users (and customers), because now instead of shipping code, a lot of us have to spend time on this thread, figuring out why stuff that just worked fine under the pages router is now a huge problem.
No one is complaining that you individually are not being helpful - you are doing a great job. But Vercel / NextJS made a big mistake shipping this too early, and it’s very frustrating, and we all wish you would put more energy into getting it truly production ready since the toothpaste is now out of the tube. This should be a code red situation. It can’t be done one project at a time. It’s not the community’s job to QA something that has been released to production.
I really like NextJS and Vercel, and I want to see you all succeed, but I think you’re committing an own goal here with how you’ve handled this roll-out. Radical candor, as they say!
Feel free to mark this off-topic if you wish.
For Tailwind CSS users: I’ve been able to find a pretty large slowdown with Tailwind CSS in general when
contentis misconfigured. This is not Next.js specific and would cause problems in any application, but since a lot of the reports nowadays are around Tailwind taking a long time to process I thought it’d be worth sharing here.Worth having a look at this thread: https://twitter.com/timneutkens/status/1783851267237781574.
Same issue here, 13.5.6 works amazingly fast (2-5seconds), but upgrading to next 14 dev compilation takes around 80-90 seconds.
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 <Link> component from next/navigation, as with the router.push (useRouter hook imported from next/navigation). We’re using Next.js 13.4.2.
i have tested running my next on multiple devices and operating systems for different projects, including , mac os, linux mint and windows and next is terribly slow, in fact a react project with webpack is way faster, i remember next js being fast, this slowness come sometime after the app router is introduced, can you please fix this shit, or use tools like vite, if the build is slow it is slow, we are actually experiancing it, stop giving us false numbers and promises
In case it helps anyone, I tried a number of things to address this in a client project. The thing that sped things up for us ultimately was the combination of:
1. Migrating the app from app router to pages router (quite easy, if you keep the same filenames - it’ll also make going back easier when this is fixed in Next.js). 2. Removing all barrel imports in our codebase. 3. Adding one
modularizeImportsrule (forlodash), though I think this had minimal effect.Before the above, average compile time was over
30s.Moving back to pages router gave us a ~30% improvement (
~20scompiles)Removing imports did nothing when I did it in isolation; but combined with the migration back to pages router, it dropped average time to
< 1sagain. 🎉Hope that helps for others running into this issue!
For us, --turbo is actually slower to compile initially than not using --turbo on next@15.0.0-canary.182:
Without --turbo
With --turbo
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.tsHas there been any updated guidance on how to proceed here? The performance has not seemed to improve from ~6mo of updates, still significantly slower than with pages router.
Is it normal for there to be that many modules?
My issue has been fixed. Switching from the app router to the pages router has significantly accelerated dev mode compilation. (Next.js@13.4.12).
Btw webpack lazy building cold is faster than turbopack 🙂 by far
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
Turbopack for development is now available as release candidate in Next.js 14.2: https://nextjs.org/blog/next-14-2
Maybe we could create a repo for this. So people can collaborate with the best-known configurations to use Modularize Imports for each package.
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.
It gets slower with each release. Not sure how much longer I can do this, sometimes 30 seconds for a page refresh. Might be time for Tanstack Start.
this issue is legit hilarious.
huge vc funded framework takes 10 seconds to render html / js / css on top of the line machines lol.
I thought it was a config issue on my machine (M2 w 16GB of RAM) but it turns out its just a ludicrous “modern” dev stack.
my solution to the issues described above is just moving away from next to something that doesn’t take hundreds of people to troubleshoot an obviously broken build system.
Hello @timneutkens ! Following the comments in this discussion, I see that you have shared screenshots of few debugger tools which help visualize the trace file (apart from the existing
trace-to-treeutility)Some examples are these https://github.com/vercel/next.js/issues/48748#issuecomment-1640153357, https://github.com/vercel/next.js/issues/48748#issuecomment-1643457679
Are there any shared steps by which we can run similar analysis? I see one of them is Jaeger but I was not able to find a way to convert the
.tracefile to one which Jaeger understands.Hey, I have the same issue using WSL2. Here is my trace file
I noticed that the first few changes work well, but after 5 - 10 minutes of making changes, the page will become stuck in a loading loop, even if next tells me that it compiled the pages successfully.
I also noticed that this issue becomes more and more visible the more files and components I have in the project.
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 🙏
same here, and in docker env is even worse, seems like is processing same files over and over without caching them.
@timneutkens : I’ve tried Next.js 14, and it’s noticeably slow. While I’m unsure of the exact root cause, it’s affecting the development team’s performance, especially when loading pages. It would be great if the Next.js team could prioritize this issue to improve the overall experience.
What my observation is when files are increasing the compilation is slowing down, I think you should cached the compile version increment compilation cache based on changes.
100%, it is unbearable to use. And it is clear there is no path to fixing it
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.
Hey @timneutkens,
NEXT_CPU_PROF=1 yarn devgives this error every time. Do u know the possible causes? Next.js version: 15.0.0-canary.179.Are you using
react-icons? Even though the next.js team says it should be dealt with via an internaloptimizePackageImportsrule, I didn’t see any improvements in loading times for it. Replacingreact-iconswith 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.
Why is Next so popular? This is unusable.
Incredible. This really solved my problem of slow development, build and deployment. My Next.js app is small, but building and compiling took about 20~40 minutes to complete.
I already used the
srcfolder inside my UI package, but due to an oversight I didn’t change the tailwind compilation rule 🥲 .@timneutkens Thanks for your post 😸 🚀.
Before
After
@jorgekorgut you can run
scripts/send-trace-to-jaegerwithcargo run /path/to/trace.txtwhich will put the trace in Jaeger, url to open it is at the start of the result.Alternatively you can run
node scripts/trace-to-tree.mjs /path/to/trace.txtwhich is more of a summary but easier to understand if you’re not familiar with the traces 👍Also facing very slow compile time using latest canary (also tried stable v14), using the app router and my guess is that barrel files (at least in my case) are what is causing the slow down.
Trace gist: https://gist.github.com/srosato/f20401047281482e25b88b4b82b588c7 (I redacted paths since its a private projet)
Without Turbo
Using Turbo
Faster, but I suspect the fact that I have a lot of barrel files is still an issue even with
optimizePackageImportsoption.I use
nx@17.2.8, tried with latesttype-graphql@^2.0.0-beta.6.Tried
--turboflag, but I get errors on TypeScript decorators withtype-graphqlon@Ctx()or even@Args().View Error
Error
Barrel files problem?
I use a monorepo with
nxand lots of barrel files. Burning the barrel files would be a heavy task and would degrade DX by exposing internal file structure of a library (though arguably DX is already down with slow compile times).Thing is, once the production build is compiled, it is very fast, thanks to tree-shaking and
side-effectsbeing set to false along withoutputFileTracing, but during development, we are hitting limits. I recognize that splitting these into micro-services within the monorepo could help for code splitting, or even using dynamic imports, but barrel files remain a problem in development (I think, maybe I am wrong) that I cannot seem to solve.I also use
react-iconsand also tried to useoptimizePackageImportsin an attempt at optimizing my barrel files like so:I have a lot of paths defined in my
tsconfig.json.View ts paths
Maybe I am doing something wrong there in order to help with barrel files, any hint welcomed.
Apple Silicon users verify Rosetta
Just going to mention this one as I’ve just discovered it. Thought I was running on native, but it appears an bad node install has ruined it for quite some time. For Apple Silicon M1(2) users only.
Make sure you are NOT on Rosetta!
If you are on x64 on a Apple Silicon your entire Node ecosystem is slowed down substantially. Steps to resolve:
archin terminalpnpm: 3.1. Wipe pnpm global env symlinks following their docs 3.2 Force install pnpm using their posix bash script on docsnode -p "process.arch"This trimmed my initial index compile time down from 2.9s to 1.5s
This got bubbled up to me and @alexander-akait, is this some sort of webpack API issue? @timneutkens
I’ve not seen any core traces to understand the regression here, but if theres something webpack related that is blocking then just ping us.
Using turbopack is a game changer, 10-30s compile times down to 0.5s!
For those who want to try it, edit
package.json:to
I confirm that next app dir on dev mode and dynamic routing are very very slow on docker now
I solved this problem by using puppeteer to go through all my route after running
npm run devusing concurrently package to both command at the same time// precompile.js import puppeteer from ‘puppeteer’; import http from ‘http’;
const routes = [ //routes ‘/’, ];
const checkServer = (url) => {
};
(async () => {
})();
In Linux 👇
In Win 😑 👇
Extremely slow.
my team and I spent the last month migrating away from next and it was totally worth it.
every team has different requirements, but for us dropping next was the right call.
@timneutkens Here’s our performance gist:
https://gist.github.com/chriscaruth/8e427460580cf44db32a17fad85f31bd (updated)
We are using next@14.2.4 due to next@canary requiring react@19.
@timneutkens Thanks for taking the time to help people here! I’m working on migrating our main web app from ejected CRA into Next and I’m running into some intense numbers for development builds.
So the main issues are: way slower restarts (no cache at all with app router?) and 18 MB client JS which takes significantly longer to load into the browser. The amount of modules is also concerning.
Switching to Turbo looks a lot better (even without cache) but sadly some quirks in my context are preventing me from jumping into Turbo now. In short:
I’ve sent you the trace in a DM on Twitter/X, I’ve looked into it myself but I’m having trouble coming to any useful conclusions (besides our app just being huge). Edit: forgot to mention one very obvious thing: there’s a lot of duplication of modules in the client bundle.
Thanks again for looking into these, I’d love to get us fully on board!
I have a similar problem. I feel like Next in dev mode is getting slower and slower as our project grows. Sometimes the navigation delay can last more than 15 seconds. This causes terrible DX, but I think the reason might be in some problematic packages, as some pages use about 20,000 modules to compile😱
I’ve also been yearning for a tool to help me debug why I have 6000+ modules compiling. I really wish I could output a log that would help me visualize the reason for so many modules being compiled so I can…remove or fix them
It would be cool if there was a
next doctorcommand that could find easy fixes like thisGlad I am not the only one having such slow build time on dev, every time I change something, a lot of unchanged components are rebuilt anyway
Any updates to try out now even if it has bugs?
This is what im dealing with rn, using tailwind, react-icons, nextjs 13.5.4 and both have no issues with dev what so ever on a nextjs 12 app (pages):
literally can go make a cup of coffee every time I route to a new page, every compile job is taking an average of 60 seconds to resolve? have also tried other versions without success
Can this be related to react-icons/tailwind not next?
In my side also got incredibly slow render just after switch from page router to app router (on next@14.0.4)
Don’t know how it’s possible but favicon.ico include 3244 modules…
Is it possible to have a more verbose log to find out which of the 4616 modules is slow?
The sluggishness is really bad.
@timneutkens it seems like the only solution here is turbopack. Keen to understand what happens if some do not want to migrate to turbo pack? Why did it get slow with app router?
That is great, so I’m assuming you’re going to share that? As otherwise we can’t investigate.
@kmvan updating next to 13.4.19 (the latest as of this writing) did actually help a lot. The dev server is back to normal. However, I experienced multiple times that the server exited gracefully automatically after a while. This happened multiple times. Then, it was possible to start the dev server but it will exit gracefully after trying to visit a page without the page loading. I looked at the processes and it turned out that the “next-render-worker-page” and “next-render-worker-app” were running multiple times.
After terminating all these “orphaned” processes, I was able to start and use the dev server again.
I’m able to reprodue this with my setup.
I’m doing some research into that direction already, but I can’t say we can definitely do that. There’re many difficulties to make it fully automatic, so for now we suggest you to configure it manually until we have a better solution.
We have exactly the same issue. Super slow the navigation, since we click the button to router.push it takes up to 7-9 secs the first time.
The problem with using TurboPack is that it still lacks some of the features like i.e i18n still, AFAIK, so not a silver bullet solution here.
I’m going to keep this issue actionable comment only so please do not pile on with comments that do not include traces / performance profiles.
You can find on how to provide traces here: https://github.com/vercel/next.js/issues/48748#issuecomment-1578374105 @feedthejim is working on adding a flag to also output CPU profiles which will allow narrowing down on potential causes further.
Since Sentry is being mentioned and also being noticeably with dev (and production) builds, im linking this issue here: https://github.com/getsentry/sentry-javascript/issues/15100#issuecomment-2720018403
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! I now can save and instant see the changes in the browser again.
What it does is it seperates the tailwind compiler from the next js and runs as a seperate process. Don’t know the exact details how this works, but it works for me.
it basically creates a new file output.css which you can import in your global.css and inside your global css you remove the:
@tailwind base; @tailwind components; @tailwind utilities;
and add it to the input.css
magically all the slow dev problems I’ve had are gone!
@mxmzb @codedpills I’ve recorded a video explaining how I looked at @T833357-SPARK’s trace: https://www.youtube.com/watch?v=PGO2szAye7A hope it helps 👍
@GriffinSauce will follow up on twitter 👍
using node 21, downgraded to 20 lts and same
One important observation i noticed, that with 14.2.4 version react-icons package works nicely (normal imports), the only insane slowdown is if I do this:
import type { IconType } from 'react-icons';this causes compile time going from 4s to 35s+.
@TONY-STARK-TECH @tangzijun @NickDev90 @tom-carbontrail please keep this issue focused on actionable comments, the initial post shows exactly what you can share so that it can be investigated and both your posts don’t include those files (trace, cpu profile, etc.). Thank you!
It helped me. Deeply appreciate. Thank you 🫡
@AhmedBaset correct, it’s an internal tool we’ve been building that we’ll be sharing at a later point, it’s not fully ready yet, but useful for us 🙂
Hey @timneutkens
Is turbo-trace-viewer.vercel.app a Vercel-internal? I can’t find how to upload a trace file
Thanks in advance
@JakeSc
react-iconspackage@react-icons/all-filesby URL: https://github.com/react-icons/react-icons/issues/593#issuecomment-1446098993import { AiOutlineSave } from "react-icons/ai">import { AiOutlineSave } from "@react-icons/all-files/ai/AiOutlineSave"As far as we know,
optimizePackageImportsis supposed to solve this, butreact-iconsdoesn’t use a barrel file, it actually defines all icons in a single js file (albeit per category), but/all-filesexports separate files. So either we misunderstood howoptimizePackageImportsworks, or it actually doesn’t work on the defaultreact-iconspackage. Which would be odd because according to the docs it is part of the default set of packages that get optimized.edit: for the record, it improved our dev server only, it did not make a difference in production build time.
@timneutkens Thank you very much! Just like @fcristel I too have Bitdefender as my antivirus, and after adding the folder to the exceptions I went from around 18s compilation time to 7s. The navigation and updates are now near-instant.
@fcristel I had a look at your trace, it seems the majority of time spent is in
@mantine/coreand@mantine/hooks, probably because your filesystem is also very slow to read files looking at all other read-file spans being slow. Can you try configuring these to be optimized so that they don’t import thousands of modules:Docs: https://nextjs.org/docs/app/api-reference/next-config-js/optimizePackageImports
Maybe request/limits in custom deployment is too low - https://medium.com/pipedrive-engineering/how-we-choked-our-kubernetes-nodejs-services-932acc8cc2be
Also, Vercel infrastructure is placed over CDN, even without cached app responses, latency can be lower because round-trip is shorter.
@leerob is there a solution to this issue or will it be a case of wait for turbo?
We are running
next@canaryand usedmodularizeImportsfor our icon import which helped a lot, but still having a painfully slow dev environment. Would appreciate your help in understanding why!cpu profiles: https://gist.github.com/vigneshka/9eff1b8b54e0139d8149114ba10ac9f4 https://gist.github.com/vigneshka/b35bd82cfef0f54b21e2a9584b4226ab
next trace and config: https://gist.github.com/vigneshka/1aaf1b7082b485acc6437955675f6e28
@timneutkens , you mentioned you are using jaeger to visualize the trace. We would also be eager to learn how to do that. Have the jaeger ui locally setup, but not able to upload .next/trace
I saw a huge gain in performance since 13.4.8 but I will throw in my trace as well if it’s still needed: https://gist.github.com/Livog/302ea9a3c78552c093e9758bed5bfa68
I went from 2min -> ~9sec, and can’t really tell why but I love it.
@aleciavogel I looked at my trace file and figured out a few painpoints maybe it helps you or anyone here. It decreased compile times for me from being not useable to now faster than before with the preloading for link tags that it does.
"@heroicons/react/24/solid": { transform: "@heroicons/react/24/solid/{{member}}", }, "date-fns": { transform: "date-fns/{{member}}", }, "react-use": { transform: "react-use/esm/{{member}}", },the interesting thing is that date-fns in particular was taking like 14sec alone to compile and all i used from that was
format()while i suspected react-icons to be the culprit it wasn’t even close.Device Info: Macbook 14inch m1 pro
I created a new sketch with Docker. It says
/pagedirectly. I can see this in the command line, but I waited a long time in the browser, no response.I created a clean page. 234ms compiled. The browser responded in 1.3 minutes.
This is happen to me, I have tab menus, everytime i navigate to new tab/menu, it takes a while, and sometimes more longer. This is really bad development experience i got in app dir, its my first time using app dir. Look at the image, 15s!
Thank you for addressing this @timneutkens!
However, the issue persists:
Next Info:
Trace: https://gist.github.com/jeengbe/f6b1bf54c04ab05bb40227c11fd90c7e
The issue can be replicated with the following repo: DigitalerSchulhof/digitaler-schulhof@
82158e8-> Copy.env.example->pnpm dev-> Head tohttps://localhost/Schulhof/AnmeldungYeah 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.
same thing here on 15.1.6
Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!
Is there no way to get a report on what is taking so long?
I am navigating a category menu which lists 64 products when a link is clicked.
When I press the
<Link/>in my browser, it gets to the address bar after 25 seconds and then the page loads.Even with a “cache hit” inside the fetch for the server component.
We experience very slow compilation times in DEV mode which is driving us crazy and not acceptable. 40 SEC waiting for a page to compile is insane… Surely we goona swich off of next ASAP…
Anyway. From this comment https://github.com/vercel/next.js/discussions/17977#discussioncomment-6108414 it turned out after we removed
react-iconscompilation time went down to 3-5 sec from 40 which is much more bearable but still significant.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)
next devrun. These timings are close to what we find in normal development..next/traceCPU.main.1736831682817.cpuprofilenext devWe’ve often seen memory limit server restarts, in case that’s relevant. For the trace above no such reboot occurred.
next infoNote we’re unable to update to Next 15 due to package dependencies (spent multiple days on this). Turbopack also introduces some odd errors, so we didn’t pursue that route much further beyond a half days work. If you expect these to have a big impact given the trace, I’m more then happy to report the issues and work through them!
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
experiemental.serverComponentsExternalPackagesand making sure they are only called in files with ‘use server’ directive.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!):
Barrel file AND my own stupidity: We use @tabler/react-icons - and ended up adding this to the
experimental.optimizePackageImportsconfig which kind of helped, but not what others experienced. Then I realized in previous attempts to fix my issue I had appliednext/dynamicto pull in my icons - HUGE MISTAKE! Dynamic was basically creating a chunk for each icon import I made of the whole tabler import - and well - yeah. Again, bad application of next/dynamic on my part. Removing all these dynamic imports gave me nearly 40% increase in compile/load times. BE CAREFUL with barrel files - and look at how you use them carefully!The other ~30% performance gain I got was from applying
experiemental.serverComponentsExternalPackagesto the new @msal/node package we use for authentication work ‘server’ side. I also refactored my use of this library to make sure it was only used in files with the ‘use server’ directive The lesson - make sure if you have big libraries that are likely server-only - you put them in that context and use that ExternalPackages feature flag to keep them out of your overall bundling process.@oalexdoda the time shown for
GETlogs includes execution of your own code, the logsCompiled inare 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:
Edit: Seems Niklas already looked at the trace too 😄
Hello 👋 @timneutkens ,
Here is the requested gist 📎 next.config , tailwind.config , trace
My development server is extremely slow taking 20 sec for content related change
I’ve spend a few hours on this, and was able to reduce the compilation time, in my case, from 60 - 70 seconds to 18 seconds (without using TurboPack).
mantine-react-tabletooptimizePackageImports;serverExternalPackages:'pdfjs-dist', 'xlsx', '@azure', '@opentelemetry', '@sentry', 'node-forge', 'pdf-lib', 'jose'.I’m not sure abou the impacts from these changes in production, so for now they are enabled only in my dev environment.
I hope this can be useful.
Reminder that all comments, regardless of being positive/negative are currently being marked off-topic if they do not include traces as shared in (multiple) earlier posts
@austinrivas I’d love to take a look at the traces for your application, similarly to others. Please see the earlier posts: https://github.com/vercel/next.js/issues/48748#issuecomment-2188574653. Can you share the trace, I’ll be able to tell you exactly why it takes 10 seconds in your particular application.
@tiriana Still waiting on your reply with a trace.
Given that these comments keep being posted without sharing traces it makes it practically very hard for me to help you. I understand that you can be frustrated by the compilation taking a certain amount of time for your application. That would also mean that you’d be interested in improving it I would assume? If so the best thing you can do is share a trace of your application. If not, that’s too bad, given that I really do want to help you. I realize I’m asking this of a cat with a bag over it’s head.
@Moe03 @tiriana please keep following the instructions for this issue in order to avoid pinging 200 people with a message that can’t be investigated by me 🙂
See my earlier replies: https://github.com/vercel/next.js/issues/48748#issuecomment-2188574653
Even if you’re having a better experience it’s still useful to share these traces, especially for Turbopack, as we track all memory usage and will be able to use these traces to optimize individual pieces.
Well said next dev with --turbo is already having an overall better dev experience than the default, also turns out i needed to upgrade to 32gbs of ram instead of my toaster’s 16 and that made it consistently much faster 😃
Rolldown will do bundling on development, something that the current Vite doesn’t do. That’s what Tims was referring to “go back to bundling”.
https://rolldown.rs/about
I was explaining why we’re building Turbopack and why we chose to build it, you’re mentioning about an API that wasn’t available in 2020 🙂
Regardless, let’s keep this issue on topic, I’d love to receive more traces from people that ignored my earlier message and still posted screenshots 😄
sadly it doesn’t help:
@iamgp could you please run Turbopack with
NEXT_TURBOPACK_TRACING=1(i.e.NEXT_TURBOPACK_TRACING=1 npm run dev(make sure thedevscript includes--turboin package.json) and share the.next/trace.logthen we can take a look at the individual hot reloads for Turbopack and tell you why it’s slow.Keep in mind that with App Router if you’re changing Server Components it means the page you’re on has to rerender which includes data fetching you’ve added, which can lead to the perception that the hot reload is slower while the actual compilation is fast and executing the code is slower because of the data fetches.
On the questions others have around
canary. The canary channel is somewhat comparable to nightly releases, they’re not marked as stable. We’re planning to release a stable version of Next.js with everything that is currently on canary in the next 1-2 weeks.Yes, next@canary also seems to be faster for me too, but I am also worried about whether this will be safe to use in prod? @timneutkens can you advise?
I have this issue as well, have tried node v18.17 and v20.10.0, on 14.2.0-canary.37 currently. Unable to generate a trace.
I have Bitdefender, after adding my project folder to the exceptions it reduce the compile time from 2.6s to 163ms
@timneutkens You are amazing!!! Can’t thank you enough!
In my case, doing this:
didn’t help. It broke the imports and I got a Mantine error.
I didn’t have Windows Defender, but I do have an antivirus: Bitdefender. I removed the working folder from the monitoring/analyzing thing that it does and now I can work again on this project! First execution time didn’t improve too much, but moving between links now goes lightning fast!
Again, thank you so much! I will take a closer look at the experimental thing also, maybe I can get it to work even faster. But for now I’m super happy with the result!
Have a great day!
@ericnation would you mind sharing the link to the article you are referring to?
Any ideas why it seems like I can’t run the CPU profiler? Running with Node v18.17.1, npm v9.6.7 and Next v14.1.2-canary.7. The same also occurs when I omit
--turbo.@ericnation every CSS module is taking 10+ seconds to compile, I’m assuming you have postcss config (i.e. tailwind) and custom tailwind config? Can you share them?
my problem fixed by deleting the lucide-react’s dynamic component
@samcx I tried removing that line from my config to reproduce the old behavior and it didn’t immediately show the slow compile times. I’m thinking there was probably another issue that was resolved around the same time that I made the config change, but it could still be related. I’ll play around with it and if I can reliably reproduce I’ll create a new issue for it.
I’ve been struggling with extremely slow dev mode builds on version 14.0.2 but adding
swcMinify: truetonext.config.jsmade a huge difference. I haven’t experienced any regressions from this change, only the performance boost.This is my full config for reference:
After banging my head against the wall for some time, can confirm downgrading from Next 14.0.3 back to Next 13.5.6 reduced the load times from ~100s back down to sub 5s on first compile for the worst page offenders, most pages compile in under 1s, thank god that subsequent renders don’t require recompilation.
Appreciate the efforts from the Next team on this and would also appreciate easier logging to identify any modules taking long time to compile. The .next/trace file apparently isn’t for human digestion.
Recently returned to nextjs to start a new project, the performance in dev is incredibly bad, no 100s for me, but 2-5s rebuilds make for awful DX out of the box, almost to extend of wanting to just run a separate builder
Here is the profiling for an upcoming product around trpc: https://gist.github.com/juliusmarminge/f0cbd590fa073ae409772d2a7a1331e7
I have had this issue for a while and finally found a fix for my usecase. I get from backend full style names for tailwind, and to do that you need to safelist the styles u want to use. I did something stupid, safelisted too much. I fixed this by being more concise about what I want to safelist.
I went from 17 sec reloads to 400 ms
By changing this:
To this:
I started facing this problem when migrating my old system to Next.
At first it was incredibly fast, even more so with the fast refresh. But after a while, configuring the monorepo, adding the UI package that used Material-UI, the application started to show a lot of slowness in route transitions in dev mode.
It took more than 1 minute for each new page accessed.
My structure worked as follows:
A monorepo containing an app/web and a package/ui. This package contained several settings and components coming from Material-UI.
So I started breaking down my application and redoing it part by part. I was able to considerably improve application loading.
Changes I made:
import { Button } from "mui-core"toimport Button from "mui-core/Button"I believe that what caused slowness on the development server was the resolution of dependencies in the package/ui. When using an external package in the monorepo, the server was resolving all dependencies of that package for each page, without need, as not all of the package was used on that page.
@timneutkens
Here is my debugging. Unfortunately, I was not able to run my application. I’ve provided the error that I received.
https://gist.github.com/kanafghan/20793c80bddf0898c72072fc5b12e9e5
I’m developing on a Windows 11 pro using WSL2 with Ubuntu 22.04. Our workspace is Nx based with more than 5k modules. After upgrading to Next.js 13.3.0, the DX has got extremely slow and we are requried to kill the dev-server often and restart in order to test. We are using both Storybook and TailwindCSS.
It seems we’re back to posting “it’s slow”, please follow the steps provided in the initial post of this issue to share the CPU profiles and traces. There is nothing we can do with “slow for me too” unfortunately.
@djaffer @mjyoung Please read the initial post in this issue. We can’t investigate/help with your particular case without the trace and cpu profiles.
Especially if you’re using material-ui you might just not know that you’re importing 11.000 (yes, eleven thousand) icons in your application. We use the trace to find what you’re doing in the application that makes it slow to compile, in the majority of cases that are now being posted (since 13.4.8) that is either you’re using TailwindCSS with a wrong content configuration which ends up scanning the filesystem (which is outside of what we can do in Next.js) or you’re importing libraries that were published in a way that causes you to import every possible file in that package (i.e. material-ui, react-icons etc.). For that case we added some default configs for libraries that were doing the most harm to compile times, including material-ui.
@HakkaOfDev I don’t see anything that stands out to me in the cpuprofile, looks like just a large amount of modules being parsed. Turbopack (when stable) will help a lot with that case.
Just want to say @timneutkens the latest
13.4.8made a huge difference in improving speed. Great work y’all!Same here. Also, on top (which slows it even more down), hot refresh falls back to a full reload more and more often in big applications.
@timneutkens
Here are the gists:
I followed the guide as closely as possible. However, after reverting all my packages back to 13.4.7, I encountered an issue where I got 2 CPU profiles and couldn’t prevent it from starting twice.
I hope this helps. Please let me know if there’s anything else you need from me.
@Livog I’d love to get both
13.4.7and13.4.8for your application as I’m curious why it was 2 minutes before.React Icons is not bundled correctly. You need to use a fork of it. I use
@sukka/react-icons-all-fileswith this modularize config:Sadly I think the latest work here https://github.com/vercel/next.js/pull/50900 (edit: actually it was done in https://github.com/vercel/next.js/pull/52031) about the support for default
modularizeImportsfor common libraries broke our setup.The error message is the following:
It seems the transformation makes it import from
antd/es/ConfigProvider, but this one really does exist just inantd.What’s even more worrying is that these
modularizeImportsare applied after the user definedmodularizeImports, so if I’m not mistaken, there’s no way for me to override these?Please let me know if there’s any workaround / fix and I’ll then share the trace files, thanks!
Just trying to contribute to people trying to get rid of slow development here: I was using
next-authand we wore usinggetServerSessiona lot in our components. This was having a massive performance impact in dev mode, because the Session token was being created up to 70 times for each request. Removing this function and handling the session in a middleware had a great improve in both build and runtime during dev mode.To say, in our experience, the app sometimes, randomly, becomes super slow, taking up to 40 seconds to load a simple page. So this is not a solution proposal, but just a tip to make things a little bit faster while this issue is not marked as completed.
@Nabwinsaud @AdrianKBL @yurimutti I’m assuming you didn’t see my earlier post that shows how you can help investigate the slowdowns in your application, can you follow the steps provided here to send us a CPU profile and trace file? Thanks in advance 🙏 https://github.com/vercel/next.js/issues/48748#issue-1680013792
@ctkc Can you provide the CPU profile too (using
NEXT_CPU_PROFILE npm run dev(replacenpm run devwith your specific dev command)@tangzijun I’ve opened #52031 with the config for ant you shared.
@VanTanev @SuttonJack @kavinvalli please try the latest canary, if you’re able to I’d love to see the traces / CPU profile with that version 🙏
@DenisBessa We’ve added a default config for modularizeImports
@alexander-akait what’s the latest on disabling the schema validation? It’s a small win (50-100ms) but does affect all applications that have CSS currently.
@TheLarkInn Thanks, will do, we’re still investigating further on if all caching is being applied and such.
@Meriegg We’d like to investigate what you’re reporting, though that is separate from this issue, would you be able to create an issue with a reproduction (could be the application you were building) in order for us to look into it? Thanks 🙏
@Jacob-Daniel Are you able to provide an application we can run? That way we can investigate what happens 🙏 This doesn’t sound related to this particular issue so maybe you can create a new issue and link this one.
Same issue. wait compiling /accounts/page (client and server)… and does not open or takes too long.
Yes in development navigating to another route takes longer and makes my system slow too . navigation route is the main issue where the performance is getting slower
@mmahalwy these two is what we use:
node scripts/trace-to-tree.mjs /path/to/.next/tracecargo run /path/to/.next/trace– you need to have Jaeger running:Here is our trace: https://gist.github.com/VanTanev/05183d70c6e54aefc704cb424b3597f9
We’re seeing 11 seconds initial build, and 3-5 seconds first rebuild.
Same experience as @JunkyDeLuxe on a M1 Pro but not using Docker.
Trace
Is there a way to visualize the
tracefile the next compiler generates?https://gist.github.com/yaronshanisima/0b1404c3b4464a3f70e612a87754daed
I mean waiting for some guy to get help, appreciated as it is, its not really a solution.
For a very small project I am getting 10 seconds development compile time per page on m1 macbook, which does not make sense. In the profiler I see the material UI packages (we did use the modularizeImports hacks), I also see things like https://www.npmjs.com/package/highlight.js for example, but its hard to understand how modules affect the dev compile times. Is the bundle size of each module have effect? is it just the amount of modules? (we have 5000 modules for some reason, again really difficult to understand why).
As time goes on, I think NextJS just adds more overhead than what it really solves, the more time goes by, the more this saying is becoming true
same for me, takes like 15 seconds to compile basic stuff, i am on @ latest and this is a problem so I can imagine what a nightmare it could be for devs using older versions
@timneutkens you can find my gist here and my trace.log here.
both don’t seem to work for me, both commands in terminal finish with
but in the developer console of my browser I see
so I think I’m currently unable to review the logs myself. I am using
"next": "^14.2.23","pnpm@10.0.0"and"node@23.6.0". I guess it’s because I’m usingWSL Ubuntu-22.04, but can’t get it to work.netstat -an | find "5747"results inreact spa for the client app and golang ssr where necessary
next-auth was abandoned in favor of ory
+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!
@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).
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):
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.
I added the following to my scripts to troubleshoot (Next.js 15 RC):
Run
dev:traceand let it load up to the page where you’re trying to troubleshoot load times, then kill the server, then runview-traceto see the flamegraph.One thing to note though that the flamegraph didn’t feel anywhere near accurate (it was claiming that
react-iconsconsumed only 10s, but it was in reality around 40s for us. However, the data was enough for us to investigate.@timneutkens I would appreciate if you could look at this gist (containing trace, cpuprofile, and next.config).
We are hitting 40-50second compile times, and extremely slow hot-reloading. Has been a terrible dev experience and have tried bundle analysis and everything and can’t find a culprit. But notice when “/” finally compiles it says its compiled (8000+ modules)
https://gist.github.com/T833357-SPARK/8f39dee84f972fb2a59ca3dd022f03a7
Thanks for the help
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.
I also had avoided going to canary as I ran into a lof of errors with react 19 when i attempted to upgrade yesterday, but I can try to get it fully up to date and, send you the results in the next day or two. Thanks
this thread has been open a year, posting traces isn’t helping either
@timneutkens Thanks for taking a look! I think you’re right; I think the slowness comes from the Vanilla Extract plugin, probably in combination with Mantine that we’re using. I’ve seen quite a few issues regarding this in their repository. I tried adding
optimizePackageImports: ['@mantine/core', '@mantine/dropzone', '@mantine/tiptap'], but it didn’t seem to help a lot. But at this point, it seems more like a webpack issue to debug rather than a NextJS one, so I suppose I’ll be taking a look into that next.Thanks for taking the time to look into this. I really appreciate it! By the way, is there an instruction somewhere on how to load those traces into Jaeger and debug by ourselves?
@timneutkens thanks for checking! Yes, I’m on Mac also my team.
Will check with our hardware supplier team in case if we are having something locked in our system which can cause file reading unbearably slow. But generally laptops are running quite fast on smaller projects of CRA or vite.
common/uiis our local UI components which within monorepo and we are installing withpnpmworkspace feature.Tbh we don’t have any custom postcss, we only have tailwindcss and everything runs based on that.
also worth to mentioned we do have custom nextjs proxy/middleware which run on each route change to detect it should load our next app pages or fallback legacy app (just redirects to that url which is external project) maybe this can cause slowness but I’m not sure. I remember once I tried to disable it, it was still slow. Probably nothing about this one is serious but worth to try to toggle it again on my side
I’ll try few scenarios based on this then can provide few more details.
@rzzapp this stands out:
.cssfiles, do you have customization (i.e. postcss)? If not it’s filesystem access being slow… which would indicate antivirus as well given that you’re on a Mac that should have fast filesystem access. Pretty much every.cssfile takes over 1 second, that’s not normal./Users/rufatzeynalli/Documents/config-app/packages/common/ui/src/index.ts@wadamek65 looking at your trace there is a lot of time unaccounted for, which would be coming from the plugins you added: https://gist.github.com/wadamek65/735f9efa17cdc50d9dcc353b099d4ac8#file-next-config-js-L1-L6. Would recommend removing these first. Also seeing slow file reads, given you’re on windows make sure anti-virus which blocks file reads is disabled on your code.
@tiriana The reason that doesn’t work is that you’re combining path aliases
@/with highly dynamic imports, which is not supported yet. If you change it to a relative path it should work 👍 Related open issue: https://github.com/vercel/next.js/issues/63372#issuecomment-2113519983I can confirm this that it was because of anti-virus in my case. My code compile time were in xxx ms , but just when “Bitdefender” was installed it sky rocket to to 20 - 50 seconds!! . Found this post and https://stackoverflow.com/a/78236532/507203 which suggested me to exclude. Right when it get excluded it goes back to ms.
@timneutkens Here you are: https://gist.github.com/tiriana/81fef8224975c9d61af46327efbb3388
This gist contains
.next/trace@timneutkens yes, it seems to be a bug. I managed to open my trace and reproduced the bug in other traces.
nameproperty in the first object in the first trace, like this[{"name":"hot-reloader","duration":25,"timestamp":714212387890=>[{"duration":25,"name":"hot-reloader","timestamp":714212387890and you will getTrace file error: Serde Deserialization ErrorIt seems that the first property in v13.5.4 istraceIdand somehow the order matters in the first object.Also, when viewing a trace sometimes I’m getting this error:
It happens because
view_rect.widthis zero, probably when there’s no data in the trace for the selected aggregation view.let pixel1 = *current * view_rect.horizontal_pixels / view_rect.width;@PILLOWPET thanks for sharing the trace, we’ll take a look! Note that it’s currently expected that if you have a certain amount of code the memory usage is higher than webpack, this is something we’re working on optimizing further. See https://nextjs.org/blog/next-14-2#turbopack-for-development-release-candidate
@dev-badace Sorry I missed your post, I just had a look and the trace shows that your disk I/O is extremely slow, for example writing the outputs takes 10 seconds per compiler. Reading files takes between 30-200ms, usually reading files from disk should take below 10ms. Do you have anti-virus enabled or something like that? That can cause such issues as it can block disk I/O on Windows
@oljimenez it’s still bundleless https://x.com/youyuxi/status/1808333856996815271
@timneutkens we have a pnpm monorepo and experimental Turbo resolve alias is not working, while running flawlessly using Webpack, without any Webpack customizations. But discussing our issue is not belonging here under this ticket, if needed we will find an existing issue or report it, totally agree on moving that to somewhere else, thanks!
@followbl We shared compile time improvements for Vercel’s website/dashboard/blog here: https://nextjs.org/blog/next-14-1#performance
TLDR:
This is measured cold, without persistent caching as that is currently being worked on.
Just a bit, I noticed it compiles a bit faster but doesn’t solve the problem, the compile time takes like 40 secs.
Sorry @timneutkens I just wanted to get a better understanding about your explanation. I hope that Turbopack will work out for Next.js and compilation fatigue will be solved. I’m struggling daily on Next.js compilation times (was not able to use Turbopack as it still has limitations) while I enjoy using other solutions with very similar feature set.
I am familiar with Rolldown which will be a replacement for Rollup and Esbuild, but the architecture of Vite will remain the same, which in my opinion is the winning strategy in most use cases.
@KarlsMaranjs Some thoughts on your trace:
@fpfx-technologies-llc\ui\index.ts@fpfx-technologies-llc\ui\config\index.ts@fpfx-technologies-llc\core\index.ts@fpfx-technologies-llc\services\index.tsdate-fnsdate-fns\esm\locale\index.js(imported fromreact-day-picker)@fpfx-technologies-llc\types\index.tsrecharts(with barrel optimization is still takes 2 seconds because it uses most of the library)@microsoft\applicationinsights-react-js@microsoft\applicationinsights-web\dist-es5\applicationinsights-web.jsreact-icons\io5\index.mjsOverall I’d say you’d benefit a lot from using Turbopack given that you’re creating a module tree that is both wide and deep so you end up benefitting a lot from the parallelization.
I’m checking this issue every day for new comments and every day I end up having to post a variant of this comment: https://github.com/vercel/next.js/issues/48748#issuecomment-2188574653
Unfortunately I’ll have to start marking these comments as off-topic and won’t be able to help you as you’re not providing what was requested @useEffects.
Sorry for just sending log lines, I wanted to check if maybe canary works, but it doesn’t. I will follow these steps and get back to you!
@timneutkens apologies, didn’t mean to rant. Thanks for helping us like this.
PMed you on Twitter with links. Prefer not to share here.
+1
It was tolerable after a recent release, perhaps the 14.2 canary that was floating around, but now it’s getting insane. Most if not all refreshes are 10s + and seem to include an INSANE number of modules. 15k plus… Surely these don’t need to be compiled each time?
It would be useful to understand what logic dictates what modules are included in which refresh, because even our favicon apparently requires a heap of imports and sometimes takes 15s to compile itself.
To be fair, eslint is also taking time to sort itself out, and I do wonder if all of this happening at once is bringing the CPU to its knees.
The trace viewer is a good step but it’s pretty hard to get a good handle on what processes are actually causing the slowdown, apart from I guess a large import tree. It feels like we need to set some standards around best practices to avoid these sorts of complex module graphs.
We’re running Inngest and tRPC which are likely causing some complex modules to be pulled in at around the same time during normal front-end navigation but to recompile everything all the time seems mad.
We would switch to Turbo but our require stack has some modules that aren’t handled. Some deep dependencies do some dynamic importing (looking at you kv), and some Node native modules the transpiler doesn’t like.
Have others found RSC / server actions etc help? Our apps are still client side which might be causing issues. Only issue is we use Chakra which isn’t supported… so yeah I feel kind of stuck!
Any thoughts or ideas appreciated.
Sent from my mobile device
On Fri, 21 Jun 2024, 9:25 pm Nick, @.***> wrote:
@katt I brought this up to the team, that’s good feedback
use --turbo caused module-not-found error .
@meds you’re using Turbopack, please follow the steps here: https://github.com/vercel/next.js/issues/48748, specifically adding
NEXT_TURBOPACK_TRACING=1and making sure you share both.next/traceand.next/trace.log, they’re separate files@MarcusHSmith seems you’ve added postcss customization and it’s taking forever to run that.
@millsoft please see the initial post of this issue, it outlines exactly how you can provide information that is critical for us to do any type of investigation if you don’t want to share the codebase: https://github.com/vercel/next.js/issues/48748#issue-1680013792.
That’s expected, it holds much more data than the
.next/traceincluding memory usage information and all data on individual function calls (hence why it’s very helpful without needing all your code).I’m getting slow hot reloads on just a default nextjs app router installation, using 14.2.0-canary.56, with or without turbopack.
Honestly, I am new to app router, but it is making me wonder whether I should be even considering it at this stage.
Gist can be found here: https://gist.github.com/iamgp/e40d0ce69d6a61de5bec3644bb3c4c4e
Alright finally now after upgrading to next@canary I’m seeing much much better loading times, DX is insanely more snappy again finally!! had to adjust tailwind, postcss files as there was some errors with them but other than that its pretty good, now my final concern is next@canary safe in production or should I only use that in dev then downgrade when I need to deploy?
I have the similar issue. I am using vanilla-extract. The initial compile time is around 250 seconds.
@timneutkens is
canarysafe enough to use for production environment?@RemyJouni had a look at yours, there’s a bunch of cases of slow filesystem for you as well, surprising (yet unsurprising tbh) both you and @fcristel have Windows paths in the trace, maybe you have windows defender enabled? It blocks each file read slowing down file reads.
Notable ones:
Hi! I’m using tailwindcss too, what you mean with
content setting of Tailwindcss is incorrect? thx!Sure thing. https://nystudio107.com/blog/speeding-up-tailwind-css-builds
Thank you so much @SuperOleg39! That was the issue, my initial resources were too small for a NodeJS application. It is still slower than the Vercel infrastructure, but as you said, it is because of CDN. Very satisfied about the improvement! 🙏
Hi Tim,
Dropping our gist here for analysis. https://gist.github.com/ericnation/347b406f96f046dc3bce856cca8955b8
I’ve been working at trying to solve this project’s slowness for days now. Driving me a bit crazy at this point 😅 Appreciate your help 🙏
I’ll have a look into that, thanks @RemyJouni!
The problem is also present in the latest canary version.
The compilation time for my landing page has significantly decreased from 19s to just 5s. Other pages that typically take around 5 seconds to compile are now taking less than one second which is great news.
However, I encountered an error related to Sanity.io, which is a bit strange since I’m following their documentation thoroughly and the project is working just fine.
I have removed
react-iconsfrom the project and the compile time decreased from 8sec to 1-2sec[ varying ]. It might help people to achieve a bit of speed if there are some less icons in their project.This issue is very easily reproducible using create-next-app@latest.
Regardless of the settings used when creating, I get extremely slow performance when running in Docker, it takes 20-30s to compile the “home” page of the demo app. The tailwind/dynamic router version takes 30s, the non-tailwind/non-dynamic router version takes 18 seconds. Running the same things locally only takes 1-2 seconds.
I am on Mac M1, with a docker that has no problem with other react/vite applications.
Heres is the dockerfile:
` FROM node:20
WORKDIR /usr/src
COPY package.json ./
RUN npm install
COPY . . EXPOSE 3000
CMD npm run dev `
Yes, you are correct! I think ver 14.x has many problems with compiling code.
https://github.com/vercel/next.js/issues/58788 Hovering a Link component causes unnecessary useParams hook re-render. #58788
@timneutkens is anybody on your team still looking at the supplied trace files?
I’ve stumbled upon this issue recently and noticed that my dev server got suddenly slow and even exploding the memory usage until node broke.
After a day of looking into this I noticed this started ocurring after using
npm linkto point one of my dependencies to a local repo.I’m running this via WSL on windows and suspect some problems with symlinking being tracked incorrectly.
Tested with both npm, pnpm and bun and both had the same issue of hanging for 70 ~ 90 seconds on dev builds.
I’m currently unable to use a locally linked dependency via
npm linkwithout this wait time.If you wish for more info I can spend some time filtering the use case, maybe if useful I can setup some minimal reproduction repositories.
@jeremypress had a look at your CPU profile, it seems you have dd-trace in the process and that is adding massive overhead spawning sub-processes. I.e.:
Besides that not seeing anything particularly out of the ordinary, you’ll likely get a big improvement when turbopack is ready.
oh no - i just did a
CMD+A CMD+Con the .cpuprofile file that got generated, but yes vscode did do some parsing, but i didn’t expect that to be included in the copied text…i’ll redo it!
@timneutkens Hey, thank you for the work on this issue. I tried updating to next@canary to see if it resolves the slowness but experiencing an issue with it not compiling my code at all. attached a file.
I updated to canary.32, and downgraded to canary.30, not working 🤷
Help?
https://github.com/FreeDrifter/next-demo/blob/main/package.json#L24
Repeat of earlier messages: Upgrade your application. 13.4.8 has big improvements but ideally upgrade to the latest version.
Hello @timneutkens I uploaded my trace files again, I updated to latest canary version but we are still experiencing dev server crashes and slow downs. Could you please take a look? Thanks
https://gist.github.com/Gr33nLight/750b3fee0cc02236fd7e357d52ff49cc
@timneutkens what would you like me to share?
Yesterday, I discovered that after eliminating a
useEffect()in a component that was causing an infinite rerenders, the dev server behaved without any issues. So I’m no longer able to reproduce the issue described here.I’ve encountered this issue when loading the app from the VSCode terminal on WSL2. However, when I run the app directly from the WSL2 terminal, it operates much faster.
i want to try and contribute, I hope it can help someone, sometimes what make nextjs slow in dev in my case is that if you add costum local font in using font face like these :
well i do that because i don’t know why i can’t add it like in the nextjs docs like these :
instead what is working for me is just adding this :
anyway using local font is indeed necessary for nextjs to have a better performance.
it goes from 3gb ram to 1,9gb ram for me
@vigneshka this might be too late for you but hopefully someone else finds it useful.
I was able to use Jaeger to visualise the trace by running the script found at canary/scripts/send-trace-to-jaeger, i.e
cargo run project-name/.next/trace.This sends each of the traces to Jaeger via Zipkin and should output the trace location with something like http://127.0.0.1:16686/trace/740938fb6baf7f87
Note that Jaeger must be running with a Zipkin port exposed,
docker run --name jaeger -p 16686:16686 -p 9411:9411 -e COLLECTOR_ZIPKIN_HOST_PORT=9411 jaegertracing/all-in-one:latest@kanafghan Try to update next?
Hello @timneutkens we are also experiencing huge slow-downs in development mode, mainly the dev server running out of memory with a message of "warn The server is running out of memory, restarting to free up memory.
Here is our CPU profiles and next config https://gist.github.com/Gr33nLight/1fcf6dd06deb6a14235abd62f28da2b4
@timneutkens I can add you to the project if you want. I am currently experiencing serious slowness in development.
@g12i looking at these there’s unfortunately nothing we can do without getting full source code access. Looking at the CPU profile it seems it’s caused by fetching many API routes in sequence which causes the compiler to stall until all routes are compiled.
@baristikir you’ll want to look at your tailwind config, it takes 1 minute and 46 seconds to run tailwind
@Livog looking at the cpuprofile the reason Babel is running is that you’ve customized the webpack configuration to run svgr/core, I’m assuming to import svgs and convert them to React components. Looking at the cpuprofile it seems to amount to something like 1-2 seconds on a cold compile. There’s not much we can do in this case as it’s custom configuration that is not part of Next.js.
Will do, thanks!
@timneutkens - Can we get heroicons added to the default
modularizeImportslist?As tailwind is recommended these days, I imagine a lot of people will be using heroicons, as it’s made by the makers of tailwind!
https://heroicons.com/
@timneutkens
Here’s a gist of the trace files after trying again on latest canary (
13.4.8-canary.13)Regarding to this https://github.com/webpack/webpack/pull/17343, schema-utils gets two updates:
validationat all - API is ready (https://github.com/webpack/schema-utils/releases/tag/v4.2.0), we need only to add an option to webpack (I think I will do it soon - this week)Saving edits causes Chrome to become unresponsive. I have to open new browser window to see changes. Terminal log outputs compiled successfully.
Tailwind wireframe project, no other dependencies. 13.4.7-canary.1 Linux OS Trace
Thanks
Thank you, this is really helpful, you save my day. In my case, it down to 1-2s. It is better rather than 15-30s!
trace + source
@timneutkens this issue here has a very good repro. #51201 All seemed to start at 13.2.5-canary.26. That issue also relates to 2 others with the same conclusion.
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 😦