-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: non-deterministic array sort (#4279)
# Description ## Problem\* Resolves #4171 We have an intrinsic sort function to do sorting on numeric arrays. It allows field elements but fail with them. At the same time we have a more generic sort_via method with works with custom ordering function but it has bad performance. ## Summary\* I have rationalised the sorting functions for arrays, we now have only one which works on any type and support custom ordering functions. The new sort function benefits from dynamic arrays and does not need sorting networks, so I was able to remove a lot of deprecated code. See below for the impact on performance. The issue 4171 is resolved by specifying the Ord trait for array elements. ## Additional Context So we have 3 sort functions: the new one 'ultra_sort' the pre-ultra plonk 'array_sort' the customisable one, 'sort_via' With this PR, we only keep the new one 'ultra_sort'. Here how it compares with the others: Sorting an array of 10 elements: - Ultra sort: 99 Acir gates, 202 UltraPlonk gates - Array sort: 235 Acir gates, 279 UltraPlonk gates - Sort_via: 1733 Acir gates, 1867 UltraPlonk gates Sorting an array of 100 elements: - Ultra sort: 999 Acir gates, 1597 UltraPlonk gates - Array sort: 6674 Acir gates, 6673 UltraPlonk gates - Sort_via: 1524713 Acir gates, 1522136 UltraPlonk gates ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
Showing
18 changed files
with
52 additions
and
749 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.