-
Notifications
You must be signed in to change notification settings - Fork 847
Optimization on checking for duplicates #10325
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, but I don't get what's the difference between iterating list via List.iteri and iterating it via double foreach. Maybe I'm missing something? What's the gain? Also, you create new tuple list and then use tuples so this code allocates more objects now while previous was only allocating fsharpfunc
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 didn't see we would end up with tuples when I suggested this. @MecuSorin maybe my suggestion was bad
Uh oh!
There was an error while loading. Please reload this page.
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.
@forki I think the idea of optimization was to split this function into two, make them recursive, one will keep track of current start (tail) and then call other, which will try to find duplicates using this tail. This way you won't be needing j > i check every time and can skip not needed iteration.
But still it needs some kind of benchmark to be sure and it's not O(n) anyway. Only way I see here making this O(n) is to make a Hashset/Map but it needs additional memory
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.
@En3Tho The optimization is about how many times the function
idfis invoked.Before for each element in the sequence,
idfwas invoked2 * ntimes that means actually2*n^2. By allocating a new list with the mapping of each element toidfwe will invoke that function just n times. The actual checking of the duplicates has the same complexity like beforeThere 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.
Tbf in all call sites is only calling the ID property. Not computing something. So after thinking about it: there is probably not much to gain here.
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 there's a lack of evidence on both sides here:
Given the lack of evidence on either side I don't think we can proceed with either accepting or closing this.
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 agree, without a proper measurement is hard to take a decision. Maybe someone with a better deeper innerworkings experience will shed a light on the thing. I don't have the time now to write a proper benchmark test.
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.
@MecuSorin , I shall close this PR, if you want to reopen it when you have time to provide some benchmarks that would be good.
Thanks for looking at this, and I look forward to seeing the perf analysis
Kevin
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.
@MecuSorin , I shall close this PR, if you want to reopen it when you have time to provide some benchmarks that would be good.
Thanks for looking at this, and I look forward to seeing the perf analysis
Kevin