-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
Fix memory leak when using multiple webpack instances #1205
Fix memory leak when using multiple webpack instances #1205
Conversation
This is fantastic work! Do you want to update the |
Done and done! 🚀 |
Seems this change breaks my build:
Had to pin the ts-loader version to 8.0.7 to work around it |
Oh no! @valerio would you be able to take a look please? @liorcode is it ThreadLoader being in the mix that causes the issue? If you remove ThreadLoader does that fix the issue? (side note; you might find your build is faster without ThreadLoader: https://blog.johnnyreilly.com/2018/12/you-might-not-need-thread-loader.html ) If you could share a minimal reproduction repo that would be helpful |
I am actually using a 3rd party service which itself uses thread loader, so unfortunately I can't control it, but thanks! |
That's a strange issue indeed, some values like I'll see if I can reproduce, @liorcode a reproduction repo would definitely help if you have an easy way to set that up! |
Have same problems after update.
my webpack config
|
I've managed to reproduce this, opened an issue here: #1206 I'll see if I can come up with a fix for this as well! |
Closes #1203
This PR should fix a memory leak issue when using multiple webpack instances that get discarded over time.
I initially converted the
webpackInstances
array to a WeakMap (plus a global index) but that wasn't enough to fix the leak, since the cachedTSInstance
held ininstances.ts
was still retaining the webpack compiler and never being freed.In the end, I removed the webpack instance array and changed the TS instance cache by using a combined WeakMap + Map so that we maintain the same behaviour but keep the lifetime of
TSInstance
s tied to the webpack compiler that spawned them.There is one small change in how
loaderOptions.instance
names are generated:0_default_e3b0c44298fc1c14
default_e3b0c44298fc1c14
They now don't contain the unique index for the webpack compiler that generated them, this shouldn't change the way instances are cached, since they are now tied to a specific webpack instance by reference (the key of the WeakMap) instead of using the index.
I've tested that the leak is fixed using this repo: https://github.com/valerio/ts-loader-leak
Memory now gets periodically freed between runs:
I thought about adding a test case in here but I don't think it would fit with the current setup, it also might be non-deterministic.