-
Notifications
You must be signed in to change notification settings - Fork 12k
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
The ng serve
command is unusually slow in v12
#21116
Comments
Here is a copy of my original post:Kind of same troubles for me... I totally recreated my project step by step in v12.0.4 and what I noticed is that adding one of my lazy loaded route added ~5min to my "ng serve" (~1min before this addition). Also this is not linked to Material in my case: I took the time to completely rewrite the Material part with the new way of using it, hopping this will change something, but it doesn't. @alan-agius4 I shared with you the newly created project in v12 in case you would like to take a look (https://github.com/hadrien-toma/angular-12-perf-troubleshooting). The last commit is the one introducing the big change, some stats on my laptop: Commit 75dfc25b64141bc2a29ee5d972393e28b2865c87: 19948ms (bases, serving was acceptable) Edits
So I don't really understand why the build and the serve operations are impacted so differently, I expected the build time to not be faster than the serve upside_down_face. Now I realize my issue is likely to not be linked to this one thinking. |
@hadrien-toma thanks a lot for sharing the project and all the details, reproductions like these are super helpful and crucial to get to the bottom of issue. Myself and @JoostK are looking at this and it appears that this performance issue is only manifested during watch mode. We'll keep you posted. |
Hi @hadrien-toma, I did take a look at the reproduction and it appears that the root cause is caused by TypeScript's incremental builder program. In the CLI for watch mode we use In TypeScript 4.3 there were several performance improvements related to the above mentioned API. However, in your case the rebuild are still as slow as using TS 4.2. However, the first cold build timing improved quite a lot. Cold Build with 57a192c6f834458ad1bd7db5c2a8669e07774690
Rebuild that changes
The above change will cause slow incremental build times. By adding the highlighted import, 138 additional TS source files are marked as affected by the change. The main reason for this is because in your case your libraries are not really libraries which have been build prior to be consumed by the application, they are just application files in a seperate directory. From compilation perspective your entire monorepo, is one gigantic application because of the architecture used here. Using the profiler, I noticed that the most time consuming methods are inside the TypeScript compiler. Therefore I then tried to build your application using TypeScript compiler directly (which uses
Therefore, following the above outcome from the investigation I suggest you share this reproduction with the TypeScript team, where ideally you remove all related NX and NG tooling to keep it as minimal as possible. |
I see, thank you very much for your time and help. So what I plan to do is:
As a side note, a workaround I am thinking of at the moment : run |
All you need to keep is the |
Ah, thank you! So I will do that 🤝 ! |
@hadrien-toma FYI, Nx has buildable libraries that result in each library having its own compilation unit. |
@JoostK Yes, in fact, in the shared reproduction all the libs are already |
Oh I was expecting it to not use that (haven't had a look at the repro yet) |
In the monorepo however libraries are consumed using path mappings directly to the sources and not the built versions. Therefore, they become part of the application compilation unit. I am not saying that compiling your libraries before will solve your issue. But in general that is expected to improve the build times of the application. Also, libraries uses a different build pipeline and therefore compiling libraries as part of an application isn’t technically correct and it can result in inconsistencies. |
Yeap, that's why I supposed it was not linked, the fact that they are buildable and publishable is more link to the final delivery process.
Yeap, and thanks to the
Interesting, I understand, thanks for the details. |
I just made another example without specifying that lazy loaded routes are |
As a workaround for the moment I am using Even if the browser is not updated automatically, the time to get the app working the first time is around 70s, which allows me to work again even if not really comfortable... |
I have done another example in v11 and the |
@hadrien-toma, as mentioned earlier this appears to be caused by TypeScript incremental API, as it can also be reproduced using I strongly suggest that you share a reproduction with the TypeScript team so that they can investigate from their end. |
Hey @alan-agius4 yes I will try to do a sharable smaller reproduction asap 😬 |
I'm having the same issue with build and serve times in a new nx monorepo project and the time oscillates between 120s to 380s. My configuration:
|
Thanks for sharing @jonastg, I will not have time to work on it recently, do you mind to share a reproduction on your side? |
I had to migrate the application back to the 11.0.3 Does anybody handle it already? |
@glebmachine, you might be experiencing a different issue. Please file a new issue including a reproduction or at the very minimum a CPU profile. You can also share the project privately like @hadrien-toma did for this issue. Regarding this specific issue, there is not much we can do since this is caused by an issue in TypeScript incremental API, which @hadrien-toma will/will report to TypeScript and provide a minimal reproduction based on his problematic project. |
Closing since for this particular issue is not actionable from our end since it's a bug inside of the TypeScript compiler. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 Bug report
Command
Is this a regression?
Yes, the previous version in which this bug was not present was 11.
Description
The
ng serve
command is unusually slow and considerably increase with the number of library (especially lazy loaded ones from what I experienced).🔬 Minimal Reproduction
I privately shared a reproduction with @alan-agius4 (link here https://github.com/hadrien-toma/angular-12-perf-troubleshooting) and I am opening this issue here in order to track it properly and to not pollute the one I originally posted in (#20713).
🔥 Exception or Error
No error.
🌍 Your Environment
Here is my
package.json
dependencies (@angular/core
installed is 12.0.4).The text was updated successfully, but these errors were encountered: