Optimize addonCacheKey computation #1102
Merged
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.
Since adoption of
ember-auto-import
v2 and ecosystem migration to@embroider/[email protected]
we seen significant performance degradation in our not that small app - it went from 4 mins to 20 mins (but with way to inefficient dependencies graph and too many cross-dependencies, which is separate problem).Debugging and profiling leads to
gatherAddonCacheKey
function being biggest contributor.First issue
Every time
@embroider/macros
addon is included (and it's included way more than few times due toember-auto-import
and many other addons depend on it) the whole tree travels happens over and over.Second issue
there is
return [...memo].join('|')
line which runs for each end every recursion level but the result is used only from top-level return when invoked withproject
as an argument.Changes in this PR propose to traverse addons three only once and build
cacheKey
string only once per project.I wasn't sure if
project
always is the same reference or there are use cases when we may have more than oneproject
during build time hence usedWeakMap
.If we know for sure
project
always is the same reference - than we can replaceWeakMap
with simple string variable that would be returned once we invokegatherAddonCacheKey
second and subsequent times.