`list.sort` enhancement proposal: Adaptivity for `binarysort`
Offen
@tim-one arbeitet bereits daran.
Seit 16.9.2025.
interpreter-core
performance
type-feature
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature or enhancement
Proposal:
Adding adaptivity to binarysort routine of list.sort.
See PR for specifics.
Initial Post (Outdated)
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:
binarysortoptionally 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
timsortcallsbinarysort- If it returns 1, then use it again next time
- If it returns 0, then use
binarysortwithout adaptivity next time - increase number of simple
binarysortruns before next attempt of adaptive run with every 0 returned
High level results
A0is currentA1is with adaptivityPmeans performance / runtimeCmeans 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.
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
- gh-138947
- gh-139342
- gh-139969
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.