-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
Delete principal from array after usage for GC #897
Conversation
On a large number of files, knip is crashing with out-of-memory. This is caused by the fact that all of the source file text and programs are being held for the entirety of the processing. There is an explicit factory.deletePrincipal being done after every principal is processed, in the `!isIsolateWorkspaces && isSkipLibs && !isWatch` case, but the `principals` array is still holding onto the principal, so the memory is not released. As we iterate through the principals, I clear the entry if it is deleted. I chose to set the principals entry to `undefined`, rather than manipulating the list, for code simplicity.
Thanks for the PR, @heystewart! The whole idea of isolated workspaces is to release this memory so i'm a bit ashamed this isn't happening. Oh well. To minimize the changes, maybe we could add something like |
No that would not be sufficient. in my use case it is failing partway through the iteration over the principals. Most of the new code is due to the typesafety since the array needs to now be undefined... |
Yes, during iteration we need to remove the current principal from the array (only in isolated-workspaces mode), but I don't really get why we have to remove the array itself? |
Ah, you mean specifically the |
PTALA @webpro ; I'm not sure if this appeases your concerns. |
commit: |
Thanks a lot for bearing with me @heystewart! Planning to release this tomorrow. |
🚀 This pull request is included in v5.42.0. See Release 5.42.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
On a large number of files, knip is crashing with out-of-memory. This is caused by the fact that all of the source file text and programs are being held for the entirety of the processing.
There is an explicit factory.deletePrincipal being done after every principal is processed, in the
!isIsolateWorkspaces && isSkipLibs && !isWatch
case, but theprincipals
array is still holding onto the principal, so the memory is not released.As we iterate through the principals, I clear the entry if it is deleted. I chose to set the principals entry to
undefined
, rather than manipulating the list, for code simplicity.