-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slow page build time in development with Next.js 5.0 (compared to Next.js 4.2.3) #3735
Comments
I am also running into this issue on a site with a custom server, 20+ pages, in local development. Some of my build times have taken over 8000ms, and sometimes they hang and nothing happens at all. Switching back to |
@iaincollins https://github.com/iaincollins/nextjs-starter/blob/master/next.config.js#L4-L19 |
Thanks Tim, that's super helpful as ever! :) I'll start with that and follow up with what @jimmmylee was saying by comparing performance with a non-custom server to see if that makes a difference too. I'd tried using the new approach for sass but didn't like the flash on initial load, but I see from another issue there is a fix for that in a call release already. I'm sure you are busy and I don't want to make an issue about any specific project of mine, but rather just try and figure out general things that might be better handled differently now, so I will do some digging with the info I have and update with what I find. |
Happy to help! Maybe we can make an upgrade guide from next 4 to next 5. There's probably more people running into this. One idea I had is to move bootstrap into a different entrypoint, and importing it in _document.js using my SSR css imports work (in an open PR on next-plugins). Not sure if it'll work, but it'd solve the issue where bootstrap is compiled every single time. |
I don't think the sass imports are root issue. I'm still getting long compile times after removing them :( |
I'm seeing super slow build times in dev mode, it there a way we could cache stuff like styles and components (like my layout that doesn't change much)? That would help a lot. |
I'm also running into this issue. It's become really slow with each hot reload. I have sass being imported into styled jsx. Is that the root cause? |
@develomark same issue, but have sass imported as module into style-loader. |
try out the latest canary < 6: hot reload build time was between 4-12 seconds edit: nvm, it's still slow |
@khuezy hot reload simply broken and not working in canary6 :) |
@plag hmm, hot reload is working for me in 6. Try canary.7, dev compile times are more reasonable. ~2-4 seconds on complete build and < 2 seconds on file change. |
Still taking me 15+ seconds to compile on my project on canary.7. Not even close to 4.2.3 yet. |
@plag @bryan it's impossible to debug |
@timneutkens It was more for khuezy's response, in case people start reading the end thinking it's fixed on the canary builds. But I'll keep my pains to a minimum. |
@bryan Did you try to remove the |
@timneutkens prepared simple projects for test In readme you can watch live examples and results. Here is average diff is 2x slower on v5. upd: canary8 - hot reload is back but still slow :) |
Since next.js 5 I also started getting mobx issues like: [mobx] Warning: there are multiple mobx instances active. This might lead to unexpected results. See mobxjs/mobx#1082 for details. I think I'll rollback for now.. |
Yeah rolling back, it's literally getting my Macbook pro to a standstill after a few hours of dev. |
This is a huge problem for me - with next 5 my builds can take upwards of 15s and my laptop grinds to a halt. On next 4 it's more like a few hundred milliseconds. |
I don't want to repeat myself. But:
|
I'll try and investigate this further - however: I have noticed my development environment is using a production React build. This doesn't occur with a fresh build of next.js (no custom Express server setup). I'm wondering if anyone with this issue is noticing the same thing? EDIT: Seems only to occur for some components (probably a React chrome extension bug). |
anyone here are using on next.config.js
maybe can be this |
Starting to feel like a robot 😅
|
Sorry I haven't had time to provide more info on this yet BTW, I will try and do more digging soon. |
@iaincollins you and @plag actually are the only ones that did provide an example 😄 |
Edit: Ok, I was wrong. Compile time dropped by 90% by removing the component imports. Ignore everything below this, I don't think my issue is related to anyone else after all. I am not sure how a component import could do this much. @gabrielmancini This seems to be the problem on my end. I went from 730 MS to 8000-16474ms. The only changes I made were setting up Semantic UI theme and importing external CSS to change the design of a simple login page. It's a consistent 10-20X increase in compile time even when only changing a single letter. Here's my next.config.js file.
Here's the branch in case anyone wanted 2 different branches to compare compile time with. |
Has anyone been able to replicate what @Attidd found? My project has hundreds of files that use component imports, and don't think I want to (or should) convert them all, especially if it's not confirmed to help. Could this be a problem with tree shaking? |
Out of desperation I tried @hipabloangel's solution from a different issue. I was able to fix my slowdown issues in 5.1 by adding this to module.exports = withSass({
webpack(config, { dev }) {
if (dev) {
config.devtool = 'cheap-module-source-map';
}
return config;
}
}); I have no idea why this works, but I guess for some reason it's expensive to generate external source maps? From some experimenting, I was also able to speed things up by removing react-material-ui SSR CSS generation (but this was before I discovered the above source map fix). |
I am also using |
@JonAbrams YES YES YES!! Thank you! Looks like source maps was reason of slowdown. 4.2.3 uses |
I can confirm cheap source maps shaved about 5 seconds of all my page loads in dev! @timneutkens is working on changing over to the |
This sourcemap change drastically improved hot reloading speeds for me (although page builds still take a while). I set my devtool option to For reference, here's the docs for this particular piece of webpack magic: https://webpack.js.org/configuration/devtool |
To confirm, I am no longer seeing this in [email protected] Thank you @timneutkens and everyone else who worked on this. 🎉 |
I'm still seeing 80-200 second HMR on the client with the latest version and everything back up to e093441
Seems to work well again. Is anything keeping an upgrade to 4.2.0 back? @timneutkens |
To clarify, if I close the tab before the hmr starts, and reopen it, it loads within seconds. If I wait until "Checking for updates on the server..." the browser freezes for at least one minute, often two minutes. I might be able to produce a minimal reproduction with some effort. |
edit: While the tweaks I made below helped, I'd still get stuck. Found this: angular/angular-cli#5775 and think Terser just wants all my memory and all my cores, exacerbated in a CircleCI multi-stage build container. For @Attidd and anyone else who landed here trying to figure out why their build is taking an extremely long time with Ultimately I removed |
I was making the silly mistake of not ignoring the next build files and nodemon was restarting over and over and resulted in long loading time. Now im happy to report hot-reloading only takes a few seconds
|
Expected Behavior
Using previous releases of Next.js build time for pages in development mode as been more or less instant (taking at most a second or two to build a page for the first time, with changes being hot reloaded instantly).
Current Behavior
When using Next.js 5.0 build times for pages in development mode are much slower, often taking several (e.g. 5-10) seconds both for initial page build and for a change to be hot reloaded.
I am seeing this same issue across multiple codebases, and someone has raised it as a performance issue against nextjs-starter project, which recently upgraded to 5.0: iaincollins/nextjs-starter#67
Steps to Reproduce
npm run dev
.npm i [email protected] --save
and start again withnpm run dev
.Context
I don't see this issue on very small sites (4-5 pages, no components) but I see it across all production Next.js sites I run, so it's not just project specific for me.
I appreciate it might still be something specific I am doing in those projects, or perhaps just because they all have more components involved.
I'm not sure how best to investigate what's causing this (and was a bit uncomfortable raising an issue without a better understanding of how to diagnose it) but as the performance is fine with Next.js 4, it seemed worth raising as an issue as I assume I'm not the only one impacted and if there are things I'm doing that can be avoided to improve performance then it's good to know what they are for others too.
Your Environment
The text was updated successfully, but these errors were encountered: