Google's new sorting algorithm is 10x faster

A portable vectorized Quicksort outperforms standard libraries across all modern CPU architectures.

7 cards · 1m 30s · tap to begin

From · · 1m 30s

Google's new sorting algorithm is 10x faster

A portable vectorized Quicksort outperforms standard libraries across all modern CPU architectures.

In brief

A portable vectorized Quicksort outperforms standard libraries across all modern CPU architectures. Using SIMD vector instructions, Google created a sorting algorithm that works across different processors while being dramatically faster than existing solutions. Originally reported by Googleblog.

Ten times faster sorting

Google released open source code that sorts arrays about ten times faster than C++ std::sort while working across all modern CPU architectures.

“sort arrays of numbers about ten times as fast as the C++ std::sort”

Why columnar databases matter

Columnar databases store all values from one column together, making filtering and sorting faster. This layout is key for SQL queries, so Google focused on optimizing it.

SIMD instructions unlock speed

Summit supercomputer

SIMD vector instructions process multiple independent elements in a single operation. AVX-512 handles 16 float32 values at once, while Arm NEON handles four, enabling massive parallelization.

“These carry out operations on multiple independent elements in a single instruction”

Partitioning is the bottleneck

Quicksort partitions arrays into smaller chunks. This partitioning step uses most CPU time, so optimizing it with SIMD compress-store instructions delivers the biggest speed gains.

“Partitioning accounts for most of the CPU time”

Portable across six instruction sets

Google's implementation works on AVX2, AVX-512, Arm NEON, Arm SVE, RISC-V V, and x86 using Highway's portable SIMD functions, avoiding 3,000 lines of platform-specific code.

Record speeds on all platforms

On Apple M1, the code sorts at 499 MB/s for 32-bit numbers. On Intel Skylake with AVX-512, it reaches 1,123 MB/s. Standard library achieves only 58 MB/s, a 9-19x improvement.

“9-19x speedup depending on the type of numbers”

New applications now possible

Sorting at 1 GB/s on a single CPU core opens possibilities for new applications. The Apache2-licensed code is available on GitHub with a detailed research paper.

At a glance

Using SIMD vector instructions, Google created a sorting algorithm that works across different processors while being dramatically faster than existing solutions.

Read the original on Googleblog

React

Sign in to react and comment.

Comments (0)

Life is short. Keep it sweet. Respect others' opinions and be kind!

    Recommended next

    More decks on google and related topics.