-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
perf(query): use quickselect instead of sorting while pagination #8995
Conversation
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 don't need to compare start == 0
- what if end is close to len(ul.Uids)
aa06b21
to
e10910a
Compare
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.
- move the quick select code to another files in the types package
- Fix the benchmarks
- Add a TODO in line 458 of worker/sort.go
- Update the description with the new benchmarks
- Add a reference to the place where we copied the quicksort code
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.
LG, minor comments
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.
lgtm
4af29dd
to
533fc9f
Compare
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.
lgtm
When we get pagination request, we still sort the entire structure and then return relevant results. This diff introduces mini select algorithm that will only sort till we get first k elements out of n. Both LDBC Benchmarks and MicroBenchmarks show that this is only useful until 50% ``` LDBC Queries Benchmarks Total elements : 300000 Current main: BenchmarkQueries/IC09/First_:20-8 1 36621508916 ns/op BenchmarkQueries/IC09/First_:304368-8 1 50905281926 ns/op BenchmarkQueries/IC09/First_:608716-8 1 63878833326 ns/op BenchmarkQueries/IC09/First_:913064-8 1 77455114015 ns/op BenchmarkQueries/IC09/First_:1217412-8 1 94143638593 ns/op BenchmarkQueries/IC09/First_:1521760-8 1 111483390712 ns/op BenchmarkQueries/IC09/First_:1826108-8 1 123910498449 ns/op ``` ``` QuickSelect: BenchmarkQueries/IC09/First_:20-8 1 32248068234 ns/op BenchmarkQueries/IC09/First_:304368-8 1 45877353021 ns/op BenchmarkQueries/IC09/First_:608716-8 1 60671818631 ns/op BenchmarkQueries/IC09/First_:913064-8 1 73447308743 ns/op BenchmarkQueries/IC09/First_:1217412-8 1 90371662972 ns/op BenchmarkQueries/IC09/First_:1521760-8 1 112880718231 ns/op BenchmarkQueries/IC09/First_:1826108-8 1 125487157700 ns/op ``` In microbenchmarks, first row is the current sort. Further rows are various different k values for the new algo ``` MicroBenchmarks Normal Sort vs QuickSelect BenchmarkSortQuickSort/Normal_Sort_Ratio_1000000_-8 1 1652489894 ns/op BenchmarkSortQuickSort/QuickSort_Sort_Ratio_1000000_1-8 1 77946322 ns/op BenchmarkSortQuickSort/QuickSort_Sort_Ratio_1000000_166667-8 1 327467804 ns/op BenchmarkSortQuickSort/QuickSort_Sort_Ratio_1000000_333333-8 1 613629295 ns/op BenchmarkSortQuickSort/QuickSort_Sort_Ratio_1000000_499999-8 1 899239726 ns/op BenchmarkSortQuickSort/QuickSort_Sort_Ratio_1000000_666665-8 1 1231191998 ns/op BenchmarkSortQuickSort/QuickSort_Sort_Ratio_1000000_833331-8 1 1565101591 ns/op BenchmarkSortQuickSort/QuickSort_Sort_Ratio_1000000_999997-8 1 1746166978 ns/op ```
When we get pagination request, we still sort the entire structure and then return relevant results. This diff introduces mini select algorithm that will only sort till we get first k elements out of n.
Both LDBC Benchmarks and MicroBenchmarks show that this is only useful until 50%
In microbenchmarks, first row is the current sort. Further rows are various different k values for the new algo