Static

Vectorized and performance-portable Quicksort (2022)

First reported by Opensource.googleblog ·

The signal ●○○○ Compiled by AI from Opensource.googleblog and Hacker News
Why you might care

Sorting millions of numbers now takes less than a second on a single CPU core.

What happened

Google has released open-source code for a vectorized Quicksort algorithm that demonstrates significant performance improvements, sorting arrays up to ten times faster than the standard C++ std::sort. This new implementation leverages Single Instruction, Multiple Data (SIMD) or vector instructions, which process multiple data elements simultaneously. The algorithm achieves its speed by efficiently partitioning data using specialized CPU instructions like compress-store or emulating them with permute instructions when necessary. This approach is portable across modern CPU architectures, including x86 (AVX2, AVX-512) and Arm (NEON, SVE), and supports a wide range of integer and float data types. Performance benchmarks show speeds up to 1123 MB/s on Intel Skylake with AVX-512 and 499 MB/s on Apple M1, outperforming prior architecture-specific sorts. The code is available on GitHub under an Apache2 license, with a detailed paper accompanying the release.

What it means

The key innovation is the portable application of SIMD instructions for Quicksort's partitioning phase, enabling performance gains previously only seen in architecture-specific implementations. By using Highway's abstraction layer, the code automatically selects the most efficient SIMD instructions available on the target CPU, ensuring both high performance and broad compatibility. This breakthrough is particularly relevant for columnar databases and other data-intensive applications where sorting is a critical operation.

This development signals a maturing landscape for high-performance computing on commodity hardware, pushing the boundaries of what's achievable with standard CPUs. The ability to sort data at gigabyte-per-second rates on a single core could unlock new possibilities for real-time analytics, in-memory databases, and machine learning pre-processing. Developers can now leverage this optimized sort for applications demanding faster data manipulation without sacrificing portability or resorting to specialized hardware.

AI-written summary. May contain errors.

Vectorized