Skip to content

optimize radixsort with simd - #8

Merged
kazeburo merged 2 commits into
mainfrom
feat/simd-radix-sort
Sep 22, 2026
Merged

kazeburo merged 2 commits into
mainfrom
feat/simd-radix-sort

Conversation

@kazeburo

@kazeburo kazeburo commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

PR Type

Enhancement, Tests, Documentation


Description

  • Adds adaptive, allocation-aware radix sorting

  • Introduces SIMD scans for amd64 and ARM64

  • Adds extensive correctness and fuzz testing

  • Documents benchmarks, portability, and usage


Diagram Walkthrough

flowchart LR
  input["Non-negative float64 input"] --> scan["SIMD or generic key scan"]
  scan --> ordered["Ordered or descending fast path"]
  scan --> adaptive["Adaptive radix strategy"]
  adaptive --> lsd["Six-pass 11-bit LSD sort"]
  adaptive --> msd["Sampled MSD partition sort"]
  ordered --> result["In-place sorted output"]
  lsd --> result
  msd --> result
Loading

File Walkthrough

Relevant files
Tests
3 files
benchmark_test.go
Expand sorting and scan benchmarks                                             
+28/-5   
radix_test.go
Add comprehensive radix correctness tests                               
+186/-0 
sorted_test.go
Extend radix input test distributions                                       
+8/-2     
Enhancement
6 files
radix.go
Add adaptive in-place radix sorting                                           
+163/-0 
radix_scan.go
Add portable radix scan implementation                                     
+21/-0   
radix_scan_amd64.go
Declare amd64 SIMD radix scan                                                       
+8/-0     
radix_scan_arm64.go
Declare ARM64 SIMD radix scan                                                       
+8/-0     
radix_scan_amd64.s
Implement amd64 SSE2 key scanning                                               
+85/-0   
radix_scan_arm64.s
Implement ARM64 NEON key scanning                                               
+72/-0   
Configuration changes
2 files
radix_scan_generic.go
Provide portable scan fallback selection                                 
+7/-0     
Makefile
Validate pure-Go build configuration                                         
+1/-0     
Miscellaneous
1 files
sorted.go
Move radix implementation into dedicated file                       
+0/-53   
Documentation
2 files
BENCHMARKS.md
Document radix performance measurements                                   
+186/-0 
README.md
Document radix implementation and benchmarks                         
+39/-2   

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Comparison

Base: main
PR: feat/simd-radix-sort

BenchmarkSampdoAll results
goos: linux
goarch: amd64
pkg: github.com/monitoring-forge/sampdo
cpu: AMD EPYC 7763 64-Core Processor                
                                        │ base-bench.txt │             pr-bench.txt             │
                                        │     sec/op     │    sec/op     vs base                │
SampdoAll/sampdo/100000/duplicates-4        1.534m ± 11%   1.170m ±  6%  -23.72% (p=0.000 n=10)
SampdoAll/sampdo/100000/random-4            3.253m ±  2%   2.184m ±  1%  -32.86% (p=0.000 n=10)
SampdoAll/sampdo/100000/wide-4              3.363m ±  2%   2.220m ±  1%  -33.98% (p=0.000 n=10)
SampdoAll/sampdo/100000/sorted-4            245.0µ ±  4%   220.5µ ±  2%  -10.03% (p=0.000 n=10)
SampdoAll/sampdo/100000/response_time-4     2.410m ±  1%   1.478m ± 16%  -38.68% (p=0.000 n=10)
geomean                                     1.582m         1.131m        -28.52%

                                        │ base-bench.txt │            pr-bench.txt             │
                                        │      B/op      │     B/op      vs base               │
SampdoAll/sampdo/100000/duplicates-4        1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.695 n=10)
SampdoAll/sampdo/100000/random-4            1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.669 n=10)
SampdoAll/sampdo/100000/wide-4              1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.354 n=10)
SampdoAll/sampdo/100000/sorted-4            785.1Ki ± 0%   785.1Ki ± 0%       ~ (p=0.098 n=10)
SampdoAll/sampdo/100000/response_time-4     1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.052 n=10)
geomean                                     1.334Mi        1.334Mi       -0.00%

                                        │ base-bench.txt │            pr-bench.txt             │
                                        │   allocs/op    │ allocs/op   vs base                 │
SampdoAll/sampdo/100000/duplicates-4          5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/random-4              5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/wide-4                5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/sorted-4              4.000 ± 0%   4.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/response_time-4       5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                       4.782        4.782       +0.00%
¹ all samples are equal

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit e091567)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit e091567

Comment thread radix_scan_amd64.s
@kazeburo
kazeburo merged commit 005ab3e into main Sep 22, 2026
4 checks passed
@kazeburo
kazeburo deleted the feat/simd-radix-sort branch September 22, 2026 07:47
@github-actions github-actions Bot mentioned this pull request Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant