~/talk

Algorithmic ideas, engineering tricks, and trivia behind CPython's new sorting algorithm

Talkat PyCon US 2023 · 2023-04-19..04-27· [python, web-performance]
links:none on file
slides:none on file

Describes CPython’s list.sort evolution from Quicksort to TimSort (a mergesort variant by Tim Peters), explains two algorithmic flaws found in TimSort (a stack overflow bug and suboptimal run-merge ordering), and shows how the Powersort merge policy—inspired by optimal alphabetic tree puzzles—reduces merge cost and was integrated into CPython 3.11.0.

AI-written summary · about

  1. 0:00Intro
  2. 0:55Outline
  3. 3:04Stable Sorting
  4. 4:03CPython Sorting History
  5. 9:18Timsort merge policy (original)
  6. 12:02Invariant trouble
  7. 13:33Timsort merge policy (patched)
  8. 14:11Timsort bad case
  9. 15:28Merge policies from first principles
  10. 17:51Mergesort meets Binary Search Trees
  11. 22:40Run-Boundary Powers are Local
  12. 25:58Some performance data
  13. 26:40Bonus: Multiway powersort
  14. 27:38Conclusion
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.