-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Adds timsort and fix issue #3265 #3616
Conversation
Besides being unsure about the unsafe code this looks good to me. It would be nice to refactor std::sort a bit more in the future. |
Did you compare the performance of this sort to any of the existing ones? |
It looks like while unique pointers work fine, the sort seems to break the refcount of managed pointers. MergeState's destructor calls |
Here are the perf numbers: The benchmark is a translation of python's sortperf.py sort benchmark |
Here's python's source: http://code.google.com/p/unladen-swallow/source/browse/trunk/Lib/test/sortperf.py |
I also checked that dtors run, so other then leaking managed pointers some of the time, everything works. |
Those are very promising numbers! |
I also double checked the managed pointer thing, and it it turns out that it works, I just wrote my refcount test wrong. It always expected a count of 1, when several tests duplicated elements, increasing the refcounts. |
This is going to need more tests. It's a complicated algorithm and all the included tests are on scalar data with small vectors. It looks to me like all the test cases cause timsort to immediately bail to the fast path, so there is no coverage for the difficult parts. Needs tests with both managed and owned boxes, and with cases that cover the different strategies used by timsort. I know it's a bit more work, but it's important. FWIW, I've poked at writing more tests a few times, but don't have enough time right now to keep at it. |
Conflicts: src/libstd/json.rs src/libstd/sort.rs
I'm hitting some ICEs with the test suite. Just updated my branch to see if it fixes things. |
Here's the backtrace from the ICE: https://gist.github.com/3834914 |
Tricky. On the one hand, I'm excited to see such improved performance; on the other it seems like "unsafe required to do sorting" is a bad sign, and I'm pretty hesitant to merge something ostensibly high-level like a sorting algorithm that has unsafe code all through it. I'm curious exactly how much the performance difference just has to do with hitting native memcpy. If it's "most", we should probably take a step back and figure out how to make vec-to-vec copies in general speed-competitive. |
The unsafe code isn't for performance, it's so the code doesn't do any copies anywhere, so that it works on non-copyable data structures. Most of the performance difference comes from doing less compares (about 40 times less than |
Broken pending #3821 |
This builds and tests for me now. On IRC we discussed reworking this to not use unsafe code, at the expense of adding a Copy bound, and I think that would make everyone more comfortable. |
+1 to removing unsafe code for the time being, at least. |
The current code is generating a lot of warnings about instantiating non-implicitly copyable types in the tests that I'm not sure how to fix. Other than that the Copy code is done. |
…nd involving pure code not being considered pure
Merged. Thanks! |
This patch doesn't have enough contact information to determine the author (and the github account associated is pretty sparse). Can we get a name and email address? |
make basic things work on Android Fixes rust-lang/miri#3608
No description provided.