-
Notifications
You must be signed in to change notification settings - Fork 29.5k
Description
Before posting a comment on this issue please read this entire post.
Previous work
The past few weeks we've been investigating / optimizing various memory usage issues. Specifically geared towards production memory usage. In investigating these we were able to find there was one memory leak in Node.js itself when using fetch()
in Node.js versions before 18.17.0
(you'll want to use 18.17.1
for security patches though).
Most of the reports related to memory usage turned out to be reports of "it's higher than the previous version" rather than a memory leak. This was expected because in order to run App Router and Pages Router at the same time with different React versions two separate processes were needed. This has been resolved by reducing the amount of processes to two, one for Routing and App Router rendering, and one for Pages Router rendering. So far we haven't received new reports since the latest release.
In some issues there were reports related to Image Optimization in production, however no reproduction was provided so it could not be investigated adequately, if you have a reproduction for that please refer to this issue: #54482
New
With the memory usage in production resolved we've started investigating reports of development memory usage spikes. Unfortunately these reports suffer from the same problem as the production memory usage issues people raised before, they're full of comments saying same issue
or posting screenshots of monitoring tools saying "Look, same issue".
Unfortunately, as you can image, these replies are not enough to investigate / narrow down what causes the memory usage, for example in multiple cases that we did get a reproduction and could investigate the reason for the high memory usage was:
- A bug in the application code, causing infinite looping components
- Accidental import of ~11.000 modules through icon libraries -- Yes, many icon libraries ship massive amounts of re-exports and those have to be bundled before it can be tree-shaken. We've been working on an automated way to split these up in
optimize_barrel
SWC transform and newoptimizePackageImports
config #54572 that should help a bit to reduce the size (and compilation speed too). - Webpack customization, e.g. adding external libraries that change webpack settings, for example to write additional sourcemaps
So far I've been able to make one small change to webpack's memory caching to make it garbage collect a bit more aggressively in #54397. I'm not expecting that change to have a big impact on the reported issues though.
We'd like to investigate these reports further, however we're unable to narrow these down if there is no code to run to collect heap snapshots and profiles for, hence this issue. If you are able to please provide runnable code of what you're experiencing.
Comments that don't include runnable code will be automatically hidden in order to keep this issue productive. This includes comments that only have a screenshot and applications that can't run.
I'm going to combine the other reports into this issue as separate comments.
I've made sure that we have 2-3 engineers on our team available to investigate when we get runnable reproductions to investigate.
Thanks in advance!