Skip to content
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

Merged
merged 4 commits into from
Oct 26, 2016
Merged

distinct perf updates #2049

merged 4 commits into from
Oct 26, 2016

Conversation

benlesh
Copy link
Member

@benlesh benlesh commented Oct 18, 2016

First commit

  • BREAKING CHANGE: changes 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.
  • BREAKING CHANGE: removes distinctKey as it's redundant.
  • Adds the minimum necessary Set implementation if Set does not exist globally.
  • Improves overall perf of distinct() by 5x in first commit.
  • Improves overall perf of distinct(keySelector) (versus older distinctKey) by 8x in first commit

Additional commit (do not flatten)

  • Refactors error handling for V8 optimization. Moves deopt only to a path that is hit if a keySelector is actually provided. This further improves perf of distinct() by another 2x (total of 9-10x), and distinct(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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 97.043% when pulling 90f478a on blesh:distinct-perf into 5460e77 on ReactiveX:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 97.043% when pulling 90f478a on blesh:distinct-perf into 5460e77 on ReactiveX:master.

@jayphelps
Copy link
Member

jayphelps commented Oct 18, 2016

commit message:

BREAKING CHANGE: distinct no signature changed, first argument is
keySelector, not comparer function.

I think the "no" was accidental. I think something like this is more clear:

BREAKING CHANGE: distinct operator has changed, first argument is
an optional keySelector and a custom compare function is no longer supported

@kwonoj
Copy link
Member

kwonoj commented Oct 18, 2016

Just curiosity - does micro perf test number shows expected gain? (I know micro perf hasn't run quite long time though..)

@benlesh
Copy link
Member Author

benlesh commented Oct 18, 2016

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.

@benlesh
Copy link
Member Author

benlesh commented Oct 18, 2016

I think the "no" was accidental. I think something like this is more clear

yup, good catch

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 97.043% when pulling df40ca5 on blesh:distinct-perf into 5460e77 on ReactiveX:master.


/**
* 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.
Copy link
Member

@jayphelps jayphelps Oct 19, 2016

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.
Copy link
Member

@jayphelps jayphelps Oct 19, 2016

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

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 97.043% when pulling 7290336 on blesh:distinct-perf into 8ebee66 on ReactiveX:master.

@jayphelps
Copy link
Member

@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
@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 97.219% when pulling 11894d0 on blesh:distinct-perf into fee7585 on ReactiveX:master.

@benlesh benlesh mentioned this pull request Oct 24, 2016
@coveralls
Copy link

coveralls commented Oct 26, 2016

Coverage Status

Coverage increased (+0.003%) to 97.217% when pulling 4f11da2 on blesh:distinct-perf into d13dbb4 on ReactiveX:master.

@jayphelps
Copy link
Member

LGTM

@jayphelps jayphelps merged commit 89612b2 into ReactiveX:master Oct 26, 2016
@lock
Copy link

lock bot commented Jun 6, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants