-
Notifications
You must be signed in to change notification settings - Fork 147
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
Use Set in uniq() When Available In Environment #395
Conversation
@@ -2258,6 +2258,28 @@ exposeMethod('uniqBy'); | |||
*/ | |||
|
|||
Stream.prototype.uniq = function () { | |||
if (!_.isUndefined(typeof Set)) { |
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.
typeof Set
is never going to be undefined
(it might be 'undefined'
), so this block will always run.
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, I know, silly mistake.
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.
We can use !_.isUndefined(_global.Set)
. We detect Symbol
for iterator support in the same way.
This looks like a big enough win that it's worth it for me. I'll let travis run before merging. |
Yep, and we're lucky we don't have to jump through the hoops Ramda does because they use value equality across the board. |
Use Set in uniq() when available in environment.
Something just occurred to me. Equality in sets is not the same as Specifically, Set uses SameValueZero, which is different from StrictEqualityComparison. Although the only difference is that We need to check for Also, I personally don't think For comparison
Edit: Typo. I meant to say that |
No, I think we should stay with strict equality as that's what |
You might have misunderstood me. For 2.x, we should definitely fix the |
No, I got what you meant, I think we should keep strict equality for 3.0; for me, |
Fair enough. |
A recent discussion on Ramda (ramda/ramda#1512) prompted me to have a look at our
uniq
function so I ported over the benchmarks from there and ran them against our code base. The results were not pretty:However, by using
Set
when it is available in the environment the performance can be improved dramatically.I normally shy away from this sort of feature sniffing but this is such an easy gain that will benefit all our users running Node 0.12, 4.x and 5.x that I think it's worth it in this case. Thoughts?