-
Notifications
You must be signed in to change notification settings - Fork 333
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
A very fast sortUsingDescriptors: #1560
A very fast sortUsingDescriptors: #1560
Conversation
I needed to sort a lot of objects and was not impressed by the speed. Sharing my improvements...
Do you have any performance improvement ratio? |
Milestone: Someday. Label: #new. What's next? A reviewer should examine this issue. |
It's around factor 4 when running the performance test cases from command line or Safari. Running a table view with 21000+ objects and sorting by clicking on column header it is a factor 2. But I guess that the table view might do other stuff then sorting..... |
We really need a unit test for this. |
Please let me know what you need for type of unit tests? There are already some in CPArrayPerformanceTest.j and CPArrayControllerPerformance.j |
Then it would be nice if you could make an app that shows the performance figures for old and new code. |
Ok, I created an ugly test Application :) |
It's definitely faster ! While testing with the current ojunit test, i noticed the native sort testing was wrong because it was not using sort descriptors. I fixed this and added tests for random numeric and text arrays. |
Awesome work! Any objection before merging it in? |
It is definitely way faster than the current Cappuccino sort, but overall not faster than native sort. Is there a reason native sorting can't be used? |
I think native javascript sorting is not stable. It will not preserve order if elements are the same. I guess Cocoa has stable sorting. This can be a reason not to use native sorting in Cappuccino. |
I found a bug. I'm not using the selector in the sort descriptor. Using compare: all the time.... |
… always using compare:
Please be sure you are testing all possible permutations of CPSortDescriptor. |
var i = [descriptors count], | ||
jsDescriptors = []; | ||
// Revert the order of the descriptors | ||
while (i--) |
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.
Here and everywhere else, please separate all control structures (and their bracketed code blocks) from surrounding code with a blank line.
@aparajita |
I'm going to merge #1562 first, then we can look into this in more detail. milestone=0.9.6 |
Milestone: 0.9.6. Labels: #acknowledged, Foundation, feature. What's next? A reviewer should examine this issue. |
So in my testing this is much faster. Interestingly sort using selector also became faster. I did some testing and this seems to be caused by the minor change of declaring In all cases except "TEXT RANDOM" with selector, the non-native version is faster than the native version in |
It looks like issue #1560 will cause a different sorting function to be used for selectors vs descriptors so performance of both should be monitored for regressions.
--- I needed to sort a lot of objects and was not impressed by the speed. Sharing my improvements...
It also seems like the Safari based application is showing pretty random results. If I click on Run I can get some results randomly 10X larger than other results. |
Great work, thanks! +#fixed |
Milestone: 0.9.6. Labels: #fixed, Foundation, feature. What's next? This issue is considered successfully resolved. |
For future reference, here are my timing results using |
@@ -425,3 +440,114 @@ var compareObjectsUsingDescriptors= function compareObjectsUsingDescriptors(lhs, | |||
|
|||
return result; | |||
}; | |||
|
|||
// Observe that the sort descriptors has the reversed order by the caller | |||
var sortArrayUsingJSDescriptors = function(a, d) |
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 know this has been merged already, but we might want to make this function more readable. All the one letter variable names are very hard to translate to a meaning and this function will be very hard to maintain for everybody that hasn't written it and even for the original author 3 months from now.
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 completely. Maybe the original author would be kind enough to make it more readable.
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'm the one who submitted the merge-sort function and it's a port from C. I can't find the original source right now but i'll keep searching.
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.
it's a port from C
That was obvious. ;-)
I needed to sort a lot of objects and was not impressed by the speed.
Sharing my improvements...