GPU-accelerated sorting for Uint32Array workloads using WebGPU compute shaders.
WebGPU Sorting is a TypeScript library and demo project that explores high-throughput GPU sorting in the browser. It ships two compute-shader implementations:
- Bitonic Sort for predictable sorting-network behavior
- Radix Sort for large
Uint32Arrayworkloads
The repository also includes a benchmark utility, an interactive demo, a custom GitHub Pages site, and an OpenSpec-driven workflow for maintaining the project coherently.
- A small TypeScript API around WebGPU setup and sorting execution
- WGSL shader implementations for bitonic and radix sorting
- Browser benchmark helpers for comparing GPU and JS sorting
- A live demo site for trying the project quickly
- OpenSpec specs and tasks for structured maintenance
npm install webgpu-sortingimport { GPUContext, BitonicSorter } from 'webgpu-sorting';
const context = new GPUContext();
await context.initialize();
const sorter = new BitonicSorter(context);
const input = new Uint32Array([5, 2, 8, 1, 9, 3]);
const result = await sorter.sort(input);
console.log(result.sortedData);
sorter.destroy();
context.destroy();| Use case | Recommended sorter | Why |
|---|---|---|
| General browser demo or medium-sized arrays | BitonicSorter |
Simple parallel sorting network and stable project reference |
Large integer arrays (Uint32Array) |
RadixSorter |
Better scaling for fixed-width integer data |
| Small arrays | Native Array.sort() |
GPU setup and transfer overhead can dominate |
| Browser | Support |
|---|---|
| Chrome / Edge 113+ | Recommended |
| Firefox Nightly | Experimental (dom.webgpu.enabled) |
| Safari 18+ | Partial; requires recent macOS |
WebGPU requires cross-origin isolation when running in the browser. The dev server is configured with the required COOP/COEP headers in vite.config.ts.
webgpu-sorting/
├── openspec/ # Specs, change proposals, tasks, archive
├── docs/ # User documentation
├── site/ # Custom GitHub Pages site
├── src/ # Library and demo source
├── test/ # Vitest suite
├── examples/ # Usage examples
├── AGENTS.md # Project-wide AI and workflow guidance
└── CLAUDE.md # Project-specific assistant guidance
npm run lint
npm run typecheck
npm run test
npm run buildOther useful commands:
npm run dev
npm run test:coverage
npm run pages:build| Surface | Link |
|---|---|
| Docs hub | docs/README.md |
| Getting started | docs/setup/GETTING_STARTED.md |
| API reference | docs/tutorials/API.md |
| Technical notes | docs/architecture/TECHNICAL.md |
| Sorting spec | openspec/specs/sorting/webgpu-sorting.md |
| Quality spec | openspec/specs/quality/project-enhancement.md |
| Current change work | openspec/changes/ |
For non-trivial changes, start with OpenSpec instead of editing files directly:
/opsx:explore → /opsx:propose → /opsx:apply → /review → /opsx:archive
See CONTRIBUTING.md for the contributor workflow and AGENTS.md for project-specific guidance.