cpython/Misc
Tim Peters bf121d6a69
GH-116554: Relax list.sort()'s notion of "descending" runs (#116578)
* GH-116554: Relax list.sort()'s notion of "descending" run

Rewrote `count_run()` so that sub-runs of equal elements no longer end a descending run. Both ascending and descending runs can have arbitrarily many sub-runs of arbitrarily many equal elements now. This is tricky, because we only use ``<`` comparisons, so checking for equality doesn't come "for free". Surprisingly, it turned out there's a very cheap (one comparison) way to determine whether an ascending run consisted of all-equal elements. That sealed the deal.

In addition, after a descending run is reversed in-place, we now go on to see whether it can be extended by an ascending run that just happens to be adjacent. This succeeds in finding at least one additional element to append about half the time, and so appears to more than repay its cost (the savings come from getting to skip a binary search, when a short run is artificially forced to length MIINRUN later, for each new element `count_run()` can add to the initial run).

While these have been in the back of my mind for years, a question on StackOverflow pushed it to action:

https://stackoverflow.com/questions/78108792/

They were wondering why it took about 4x longer to sort a list like:

[999_999, 999_999, ..., 2, 2, 1, 1, 0, 0]

than "similar" lists. Of course that runs very much faster after this patch.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2024-03-12 19:59:42 -05:00
..
NEWS.d GH-116554: Relax list.sort()'s notion of "descending" runs (#116578) 2024-03-12 19:59:42 -05:00
rhel7
ACKS gh-89547: Support for nesting special forms like Final (#116096) 2024-03-11 23:11:56 -07:00
coverity_model.c
externals.spdx.json gh-112844: Add SBOM for external dependencies (#115789) 2024-02-29 17:38:04 +02:00
HISTORY Fix a misspelling of Interpeter -> Interpreter (GH-111040) 2023-10-18 15:09:45 -07:00
indent.pro
platform_triplet.c gh-71052: Change Android's sys.platform from "linux" to "android" 2024-03-11 19:25:39 +00:00
Porting
python-config.in bpo-45101: Add consistency in usage message IO between 2 versions of python-config (GH-28162) 2024-02-26 22:04:44 +02:00
python-config.sh.in bpo-45101: Add consistency in usage message IO between 2 versions of python-config (GH-28162) 2024-02-26 22:04:44 +02:00
python-embed.pc.in
python.man gh-116167: Allow disabling the GIL with PYTHON_GIL=0 or -X gil=0 (#116338) 2024-03-11 11:02:58 -04:00
python.pc.in
README
README.AIX
README.coverity
README.valgrind
sbom.spdx.json gh-116116: Backport blake2 change to fix building with clang-cl on windows-i686 (GH-116117) 2024-03-04 16:59:57 +00:00
SpecialBuilds.txt gh-108634: Py_TRACE_REFS uses a hash table (#108663) 2023-08-31 18:33:34 +02:00
stable_abi.toml gh-114626: add PyCFunctionFast and PyCFunctionFastWithKeywords (GH-114627) 2024-02-15 11:05:20 +01:00
svnmap.txt
valgrind-python.supp gh-105182: Remove PyEval_AcquireLock() and PyEval_InitThreads() (#105183) 2023-06-01 13:41:56 +02:00
vgrindefs

Python Misc subdirectory
========================

This directory contains files that wouldn't fit in elsewhere.  Some
documents are only of historic importance.

Files found here
----------------

ACKS                    Acknowledgements
HISTORY                 News from previous releases -- oldest last
indent.pro              GNU indent profile approximating my C style
NEWS                    News for this release (for some meaning of "this")
Porting                 Mini-FAQ on porting to new platforms
python-config.in        Python script template for python-config
python.man              UNIX man page for the python interpreter
python.pc.in            Package configuration info template for pkg-config
README                  The file you're reading now
README.AIX              Information about using Python on AIX
README.coverity         Information about running Coverity's Prevent on Python
README.valgrind         Information for Valgrind users, see valgrind-python.supp
SpecialBuilds.txt       Describes extra symbols you can set for debug builds
svnmap.txt              Map of old SVN revs and branches to hg changeset ids,
                        help history-digging
valgrind-python.supp    Valgrind suppression file, see README.valgrind
vgrindefs               Python configuration for vgrind (a generic pretty printer)