-
Notifications
You must be signed in to change notification settings - Fork 121
feat: introduce @list.sort_v2 to improve sort stack safety #2154
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
base: main
Are you sure you want to change the base?
Conversation
Stack overflow fix by avoiding recursive implementationCategory smaller.sort().concat(More(x, tail=greater.sort())) New: let arr = self.to_array()
arr.sort()
from_array(arr) Recommendation Test case could be more comprehensiveCategory test "sort-stack-safety" {
let arr = FixedArray::makei(100_000, fn { x => x })
arr.rev_inplace()
let ls = @list.of(arr)
ls.sort() |> ignore
} Recommendation Documentation needs updatingCategory /// assert_eq(ls, @list.from_array([-76, -6, 0, 1, 3, 6, 52, 123])) Recommendation |
Pull Request Test Coverage Report for Build 6927Details
💛 - Coveralls |
I think you can either:
|
The original implementation has a 3-constant factor, I think replacing it would count |
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
The test seems a bit oversized, which may slow down the standard library's test suite. If it's for correctness, 100,000 might be overkill, and if it's only for speed measurements, maybe we can delete it after? |
sorting 100_000 elements should be fine, we may add some attributes to allow test filtering mechanism in the future @Erchiusx can you do a rebase to keep the history clean |
100_000 is not a must, 100_00 is enough to show the difference perhaps I should change it to 100_00? |
The rebase is done, but seems still squashable |
Later on, I will establish a core-extra-test repo with interns from @plct-lab to conduct some stress tests on the core. The testing in the core can be relatively reduced. cc @CAIMEOX |
Previous @list.sort would yield a stack overflow at a data scale of 100_00
introduced @list.sort_v2 which uses @array.FixedArray::sort to help sorting the list