Change the Implementation of get() in MultiItemCache to Prevent Stack Exhaustion #15047
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One of the projects I'm on at work has such a large number of outputs (currently 1400 and growing) and that is causing webpack to crash during compilation. You can see in the stack trace starting here that the same 6 lines repeat a little over 1200 times until the stack is exhausted. This is because the MultiItemCache in lib/CacheFacade.js uses recursion to iterate over it's item list when you call get(). This implementation prevents stack exhaustion both in the included unit test and in my testing with our project. I'm sure it could be more elegantly written but I've taken care to avoid behavioral changes other than preventing our use case from blowing the stack.
What kind of change does this PR introduce?
This is a bugfix for a probably-rare case in which a large number of outputs causes compilation to exhaust the interpreter stack.
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
What needs to be documented once your changes are merged?
Nothing that I'm aware of