-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Note:
- This is POC that this has a observable impact.
- This is subject to further calibration and optimizations, but high level concept is dicusable.
- Will issue PR shortly.
Rationale
Galloping provides adaptivity when merging runs.
However, underlying binarysort
always does O(nlogn)
.
Concept
The concept is simple:
binarysort
optionally does adaptive routine.- It has a mechanism to switch it off during the run and go to simple binarysort
- It returns 1 if it has completed full data with binary routine and 0 otherwise
timsort
callsbinarysort
- If it returns 1, then use it again next time
- If it returns 0, then use
binarysort
without adaptivity next time - increase number of simple
binarysort
runs before next attempt of adaptive run with every 0 returned
High level results
A0
is currentA1
is with adaptivityP
means performance / runtimeC
means comparison count- Aggregate numbers for all datasets combined are in the title
- Plain integers and floats

- Integers and floats wrapped in
list
, so comparisons are__lt__
calls, thus more expensive

So the benefit is higher when comparisons cost more.
But there is some benefit for optimized comparisons as well.
Worst case
- Adaptive
binarysort
does ~20% more comparisons than simplebinarysort
for random data. - However, it detects that it is not paying off after about 30 iterations.
Thus the worst case would be random data up to size 30, which would be 20% slower.
Size 60 would only be 10% slower.
Size 120 would only be 5% slower.
And so on...
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/sorting-adaptivity-improvement/103700
Linked PRs
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement