The implementation of Powersort in
CPython began with version 3.11, replacing the older Timsort algorithm. The change was motivated by Powersort's superior performance and stability. The core implementation can be found in the CPython source code within the file, where the list-sorting functions are defined. The detailed merge policies and algorithm are described in ... The transition to Powersort involved addressing issue #78742 in the CPython repository. The
PyPy project, known for its high-performance Just-In-Time (JIT) compiler for Python, also integrated Powersort. The relevant commit, identified as `6d2f7a78baa8d4d2f94f5fb709f697a560b45f4e`, details the inclusion of Powersort into PyPy's list-sorting functions. In
AssemblyScript, Powersort was integrated to enhance the performance of WebAssembly applications. The relevant pull request, #1904, and the implementation details can be found in the file within the AssemblyScript standard library. These implementations across different platforms highlight the adaptability and efficiency of Powersort in various programming environments.
Implementations As with TimSort, the full implementation of Powersort is hundreds of lines and too large to fit in a Wikipedia article. Readers are advised to consult the following sources: • C implementation from
CPython version 3.13.5. Starts on line 1577 and ends on line 3151, for a total of 1574 lines (974 excluding comments and blank lines). • Python implementation from
PyPy3.11 version 7.3.19. 680 lines (434 excluding comments and blank lines). This code still uses the name "TimSort", but the merge strategy has been changed to "powersort". == Comparison with Timsort ==