react-refresh-webpack-plugin icon indicating copy to clipboard operation
react-refresh-webpack-plugin copied to clipboard

Memory cleanup doesn't happen on incremental compiles

Open gaganpreet-toddle opened this issue 1 year ago • 3 comments

When using react-refresh-webpack-plugin,

On incremental compiles (making changes in codebase and then saving, triggering a recompile), we observed that the memory increases a lot while the recompile is taking place and once it is done and the changes are reflected on the browser, the memory doesn't go down to anywhere around it was before (garbage collection). Due to this, each incremental compile adds on around 400-500MB which leaves around 300-400MB unretrieved, resulting in high memory consumption after a few recompiles and working on an 8GB mac becomes very difficult where webpack started with consuming 5GB in the beginning and after a few incremental compiles, it reaches to 6.5GB.


On the other hand, when we use react-hot-loader, the garbage collection is very ideal. During incremental compile, it consumes additional 300-400MB, which it leaves almost fully within 5-10secs after the compile is done. Memory doesn't pile up at all.


Would be great if you could take a look. Thanks!

gaganpreet-toddle avatar Apr 01 '24 12:04 gaganpreet-toddle

Do you have a sample repo that we can look into?

pmmmwh avatar Apr 25 '24 08:04 pmmmwh

Hey, no sample repo as of now. We were using it in our company repo which is very large, something around 25k modules. Building a sample this large is tough and I guess this kind of replication is only possible when your app is testing limits of our machine. Also currently I am very hard pressed on time. It would be great if you could try to take a look. I'll try to build a sample reproduction in a few days when I get time.

gaganpreet-toddle avatar Apr 25 '24 14:04 gaganpreet-toddle

In v0.5.13 there's a change that may or may not help with the memory pressure problem - I suspect the issue here is either related to Webpack's in-memory file system, or how we cache "module type" (CJS vs ESM) for paths. I'll try to make some time next week to see if I can create a repo big enough to see this hike + do some memory profiling.

pmmmwh avatar Apr 27 '24 22:04 pmmmwh