-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
[WIP] fix: deepCopy
memory leak
#2654
[WIP] fix: deepCopy
memory leak
#2654
Conversation
This needs some more work, seems like I broke it while cleaning up before committing.. |
I think you can't do it this way, as it destroys the reference to the object. I can suggest using return des;
//...
targetMessage = deepCopyIteratively(message, targetMessage); ? There's another problem: even after implementing my suggested changes, the translation still doesn't work on the client side. Something else is broken. By the way, my latest version worked fast, even without a cache. However, there's a significant problem with using a cache: if someone messes up the structure of the translations, it could lead to a leak again, which would be very difficult to trace. Logically, the cache should not be implemented in deepCopyIteratively, but at a higher level, to cache the result of deepCopyIteratively, similar to how it's currently done with loader.cache. This would simplify the code but could theoretically cause leaks. |
Yes something like that is the eventual goal, we also want to stop passing the
Are you referring to the changes in this PR intlify/vue-i18n#1675? If so, have you tested this with locale files containing nested keys as well? Testing locally I can confirm it is fast with arrays, but using nested keys ends up being quite slow compared to the original code (as long as you aren't triggering the leak). I'm testing with this file en.json.
I'm not sure what you mean with this.
Maybe I misunderstand, do you mean the eventual merged result of all files per locale? This wouldn't work in combination with dynamic locale resources such as those returning API results, but it would work if all locale files were static files. I'm trying to cache the intermediate merges, if a project has a locale configured with |
I tested on this repo. In the pull request, I switched to using Object.assign, and after that, not only did the leak go away, but the speed also significantly increased.
Global maps with objects can also cause leaks; probably, we need to think through a cleaning algorithm
Yes, you are right. I forgot about that. |
π Linked issue
β Type of change
π Description
Proof of concept to prevent memory leak based on findings from #2647 and #2629
This adds a changed
deepCopy
function, this version attempts to merge and copy objects by value. I added simple caching to prevent unnecessary merging as this is CPU heavy and changed the function to use iteration instead of recursion to lower memory usage.I haven't tested this with dynamic message files or files with cache disabled. I also want to refactor the way messages are cached and merged as mentioned in #2647, but the first priority is tackling the memory leak.
π Checklist