-
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 operator performance issues. #2009
Comments
"RxJS version: most recent" Please be specific: Is it RC1? |
https://github.com/ReactiveX/rxjs/blob/master/src/operator/distinct.ts#L68-L73 Whatever version this would be is using the for loop which will lead to the poor performance. |
@bafolts Yeah, that is a problem. I'm surprised it made it this long without being pointed out. The I should have a PR for this later today. We'll probably:
|
My completely unscientific testing suggests to me that we should indeed utilize a set of some kind, ideally in modern browsers use an ES6 Set and but fall back to an array with an Again, not scientific but I feel pretty safe in my belief that Sets are super fast compared to any approach that uses Arrays--at least in Chrome. And it makes sense too cause the underlying runtime can implement a true HashSet instead of needing to loop through all the items.
The downside to using this would be that we could no longer accept the same In some distant future when we only support IE11+ we could accept a compare function that is provided the Set and then expected to do something with it to decide if the value is distinct, like the default Would love to hear others thoughts on this and if they have alternative, IE9+ supported solutions. Without proof, I feel that 99% of people using |
A set is definitely the way to go. Instead of a
Internally IE9 can now use the poor man's hash from days of yore |
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. |
RxJS version:
5.0.0-rc1
Code to reproduce:
Create a distinct observable with 100k unique items, it will progressively get slower as internally a serial search for the item is used.
Expected behavior:
This code should finish under 1 second.
Actual behavior:
This code takes minutes to run.
Additional information:
The internals of
distinct
needs to utilize a set to determine if the item has already been observed. The serial search will not scale. I stumbled upon this issue by not fully understanding howdistinct
worked.The text was updated successfully, but these errors were encountered: