Virtual-Memory
Powersort

Stable, run-adaptive mergesort with O(√(n log n)) extra space instead of a buffer for n/2 elements.

Finn MoltmannTamio-Vesa NakajimaSebastian Wild

Philipps-Universität Marburg

ESA 2026
Virtual-Memory Powersort · ESA 20261 / 5

1 · powersort

Powersort merges runs in nearly optimal order

44454647484950414243403933343536373817181920212223242526272829303132111213141516107891234561223333444444445555555555555555345213243
Runs. One scan finds the already sorted runs.
Powers. The interval between two run midpoints drops onto a tree; the pole it hits is the boundary’s power.
Stack. A smaller power triggers merges. Cost ≤ n(H + 2); in CPython since 3.11.

the catch

Every Timsort / Powersort implementation merges through a buffer of n/2 elements. Merging in place exists — but is several times slower.
Virtual-Memory Powersort · ESA 20262 / 5

2 · virtual-memory powersort

Runs are lists of pages, scattered over memory

input array A — 10 pages of P = 4extra pages B — 4 pages (≈ lg n + O(1))A0A1A2A3A4A5A6A7A8A9B0B1B2B3ABfree pages (top first): A0 B1 B2 B3logical view — runs as lists of pages (label = physical page)current run — run 1 · 12 elements, 1 pageB0
one color per run · free page · not yet scanned · n = 40, P = 4
123456

extra space lg n + O(1) pages
  = O(√(n lg n)) elements
moves M + 3n · comparisons M + n
Virtual-Memory Powersort · ESA 20263 / 5

3 · experiments

Quadratically less memory, negligible slowdown

extra memory · int (36 MB)

CPython-style18 MB · 50 %
Inplace-MergeO(lg n) · ≈ 0
Virtual-Memory1 MB · 2.8 %
Pingpong36 MB · 100 %

120-byte records (1 GB input):
6 MB instead of 543 MB.

running time · int

running time · 120-byte records

Virtual-Memory Powersort · ESA 2026 · n ≈ 10⁷, x-axis: presortedness (expected run length)4 / 5

more

Paper, code & interactive demos

paper page

Full paper, code and data.

wild-inter.net/publications/
moltmann-nakajima-wild-2026

interactive demo

Step through Virtual-Memory Powersort on your own inputs — Pingpong Powersort, too.

power-sort.github.io/
virtual-memory-powersort

→ Come by the poster for Pingpong Powersort and all four data types.

F. Moltmann, T.-V. Nakajima, S. Wild: Virtual-Memory Powersort. ESA 2026, LIPIcs 388, 14:1–14:17 · doi 10.4230/LIPIcs.ESA.2026.14 · code git.sr.ht/~tamionv/vm-powersort

#PowerSort — adaptive_ stable_ sorting_5 / 5
→ / space: next · ←: back · P: pause · R: replay · F: fullscreen