-
Notifications
You must be signed in to change notification settings - Fork 3k
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
distinct
perf updates
#2049
distinct
perf updates
#2049
Conversation
commit message:
I think the "no" was accidental. I think something like this is more clear:
|
Just curiosity - does micro perf test number shows expected gain? (I know micro perf hasn't run quite long time though..) |
Yes... ~9-10x faster in micro perf test than previous. |
yup, good catch |
|
||
/** | ||
* Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items. | ||
* If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted. | ||
* If a comparator function is not provided, an equality check is used by default. | ||
* As the internal HashSet of this operator grows larger and larger, care should be taken in the domain of inputs this operator may see. | ||
* An optional parameter is also provided such that an Observable can be provided to queue the internal HashSet to flush the values it holds. | ||
* @param {function} [keySelector] optional function to select which value you want to check as distinct | ||
* @param {function} [compare] optional comparison function called to test if an item is distinct from previous items in the source. |
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.
@Blesh Need to remove this I believe?
@@ -5,29 +5,33 @@ import { TeardownLogic } from '../Subscription'; | |||
import { OuterSubscriber } from '../OuterSubscriber'; | |||
import { InnerSubscriber } from '../InnerSubscriber'; | |||
import { subscribeToResult } from '../util/subscribeToResult'; | |||
import { ISet, Set } from '../util/Set'; | |||
|
|||
/** | |||
* Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items. | |||
* If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted. |
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.
@Blesh docs need to be updated to not describe the compare function and instead include the keySelector
@Blesh is going to update the jsdocs, then we'll merge. |
… perf improvements - Adds a limited Set ponyfill for runtimes that do not support `Set` - `distinct` now supports an optional keySelector argument that the user can use to select the value to check distinct on - `distinctKey` is removed as it is redundant - `distinct` no longer supports a comparer function argument, as there is little to no use case for such an argument that could not be covered by the keySelector - updates tests to remove tests that do not make sense and test new functionality BREAKING CHANGE: `distinctKey` has been removed. Use `distinct` BREAKING CHANGE: `distinct` operator has changed, first argument is an optional `keySelector`. The custom `compare` function is no longer supported. resolves #2009
- moves keySelector call to a different function with a try catch to improve V8 optimization - distinct calls with no keySelector passed now take a fully optimized path, doubling speed again related #2009
LGTM |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
First commit
distinct
to use a keySelector and NOT a comparer. Comparer check was to mimic RxJS 2 or 3, which was the current version when this operator was originally created.distinctKey
as it's redundant.Set
implementation ifSet
does not exist globally.distinct()
by 5x in first commit.distinct(keySelector)
(versus olderdistinctKey
) by 8x in first commitAdditional commit (do not flatten)
distinct()
by another 2x (total of 9-10x), anddistinct(keySelector)
slightly (total of 9x)Note
comparer
function argument exists in Rx4, yes, but after discussion with @mattpodwysocki, we are removing it because it is of little use, and most use cases could be solved by the keySelector. We can add it at a later time if we choose with minimal breakage.