Closed BTMorton closed 5 years ago
Thank you for taking the time to do this! I just made some major changes this past week that partially address this, but I will also go a step further and make sure that it's documented and that the object is only added if specified by the user for debugging.
done, braces was refactored and no extra properties are added to the result array.
Currently, after doing an expansion, you attach the result object returned from the compiler on the array object. This then gets put into the cache object which takes up a significant amount of memory, particularly when the cache grows large, as it creates a new compiler for each call which is cached, leading to a ~5/6mb overhead every time.
This result property does not appear to be documented behaviour and after a quick github code search, I couldn't find any references to it. Could you either remove this property, make it an optional addition, or suggest a third option to help mitigate the memory usage?
I am currently using chokidar to watch media files for changes, on a folder with ~50k items in it. This leads to the cache object holding ~300mb of memory at ~60% of my total application's memory usage.
Example program to try to demonstrate the issue:
Running the above using node --expose-gc bracesTest.js on my testing file system gives the following output:
My testing system is created using symlinked media files into a single folder with the following script:
Screenshot of the memory snapshot that led me to the cache:
Screenshot of the memory snapshot after adding a
.slice()
call to thememoize
method when adding an item to the cache: