Cache individual programmatic descriptors along with the overall list. #8494
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.
We added caching for presets early on for Babel 7. These caches affect how often a plugin/preset's overall function is re-executed, and come in three flavors:
Invalidation, and thus re-execution of these functions, has been managed differently for each of these. Up until this PR, invalidation of programmatic options has been purely based on the identity of the array itself, so if you did
it would only evaluate the env preset's function a single time.
then each call would have a different array, even though the contents were identical, and the preset function would be evaluated twice.
This PR changes the second case to still only evaluate the preset a single time, even in the second case. When I originally wrote the caching, I was on the fence about how aggressive to be here, and how much power to give to users. Over the course of 7.x's beta, I've come to the conclusion that expected usage will mean that the behavior without this PR would result in too many re-executions of the plugins/presets, and thus reduced performance.
With this PR, we preserve the old behavior, so if you give exactly the same array, it will still be the fastest, but if you give two different arrays, we'll still do our best to recognize that it is actually exactly the same preset both times, and avoid re-executing the preset.
Note, this still relies on object identity for the preset/plugin and the options object, so if you do
this will still run the preset twice, because it has gotten two entirely different options objects. I think that is acceptable and more along the lines of what a user might actually expect, so I don't think it's too bad. It seems too aggressive to actually try to deep-compare the options objects themselves, since that could incur a bit of a performance hit.