-
Notifications
You must be signed in to change notification settings - Fork 35
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
fix(index.js): avoid creating a new object in reduce loop #14
Conversation
Partially reverts e583186
...acc, | ||
[usedFilepath]: usedFilepath, | ||
}), {}); | ||
const fileDepsBy = compilation.fileDependencies.reduce((acc, usedFilepath) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const fileDepsBy = new Set(compilation.fileDependencies)
should theoretically be much faster. I'd be very interested to see the results!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, even this approach is now 1ms vs. ~2s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the mutating reduce is 1ms, or the Set is 1ms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mutating reduce. O(n) mutation isn't terrible compared to O(n^2) Object.assign! Though you might get sub milliseconds on native Set usage... haven't tried it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth using Set
if only to avoid the eslint override :-) but it'd be great to try it and determine if it's significantly better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is an example of this new Set
method you refer to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. Really hates the impure penalty.
@@ -26,6 +26,8 @@ | |||
// Variables | |||
"no-use-before-define": [2, "nofunc"], | |||
"no-unused-vars": [2, {"args": "none"}], | |||
// Performance Considerations | |||
"no-param-reassign": [0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I'd prefer disable this using single line comment
[usedFilepath]: usedFilepath, | ||
}), {}); | ||
const fileDepsBy = compilation.fileDependencies.reduce((acc, usedFilepath) => { | ||
acc[usedFilepath] = usedFilepath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe switching to _.set(acc, usedFilepath, usedFilepath)
could just skipping the eslint error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @ljharb's suggestion of using Set is right move long term. Just wanted fast rebuilds back first so thanks for merging!
Released v3.0.2 |
As outlined here, avoiding parameter reassign by creating a new object occasionally can cause performance issues. This happens to be one of those cases!
This partially reverts e583186
Please see below for performance implications for an 1800 module webpack run!