Zero-copy SIMD sorting for TypedArrays and NumPy arrays across Apple Silicon NEON, AVX2, AVX-512, and SVE. Saturating vector lanes at over 600 Million elements/second.
npm install vector-qsort
pip install vector-qsort
How Google Highway achieves consistent sub-millisecond execution without recompilation.
Base sorting for sub-arrays under 128 elements is mapped directly to branchless SIMD compare-and-swap sequences, eliminating CPU branch predictor flushes entirely.
The same C++ binary queries CPUID or AT_HWCAP at startup and targets ARM NEON (128-bit), x86 AVX2 (256-bit), or AVX-512 (512-bit) with zero runtime translation overhead.
Large arrays (up to 100M items) can be sorted non-blockingly using vsort.async(), dispatching execution to background libuv worker threads without stalling Node's event loop.
Both the Node.js N-API binding and Python pybind11 module operate directly on raw contiguous memory pointers, preventing serialization, copies, or GC pauses.
Ready-to-use snippets for Node.js, Python, and C++ Google Highway dispatcher.
import vsort from 'vector-qsort';
// 1. In-place SIMD sort on Float32Array (mutates buffer)
const f32 = new Float32Array([3.14, -1.5, 42.0, 0, -100.5, 2.71]);
vsort(f32);
// Result: Float32Array [-100.5, -1.5, 0, 2.71, 3.14, 42]
// 2. Descending sort
vsort(f32, { desc: true });
// 3. Non-mutating copy
const sortedCopy = vsort.sorted(f32);
// 4. Off-thread background sort on libuv worker pool (zero event-loop blocking)
const largeBuffer = new Float32Array(10_000_000);
await vsort.async(largeBuffer);
import numpy as np
import vector_qsort
# 1. Allocate contiguous 1D NumPy array
data = np.array([3.14, -1.5, 42.0, 0.0, -100.5, 2.71], dtype=np.float32)
# 2. In-place SIMD sort (zero memory copy)
vector_qsort.sort(data)
# 3. Descending order
vector_qsort.sort(data, desc=True)
# 4. Non-mutating sorted copy
sorted_copy = vector_qsort.sorted(data)
# Supports float32, float64, int32, uint32, int64, uint64, int16, uint16
#include <hwy/highway.h>
#include <hwy/contrib/sort/vqsort.h>
// Generic vectorized quicksort wrapper over Google Highway VQSort
template <typename T>
inline void VectorQSort(T* data, size_t size, bool desc = false) {
if (size <= 1) return;
// Dynamic runtime dispatch to NEON, AVX2, AVX-512, or SVE
if (desc) {
hwy::HWY_DYNAMIC_DISPATCH(hwy::VQSort)(data, size, hwy::SortDescending());
} else {
hwy::HWY_DYNAMIC_DISPATCH(hwy::VQSort)(data, size, hwy::SortAscending());
}
}
# Run Node.js micro-benchmarks against native V8 .sort()
cd node
npm install
npm run bench
# Run Python micro-benchmarks against NumPy np.sort()
cd python
pip install -e .
python bench/bench_sort.py