Beating CoreCLR's own C++ code with CoreCLR 3.0 intrinsics
summary
Rebuilds CoreCLR's quicksort partition in C# using .NET Core 3.0 hardware intrinsics (AVX2, 256-bit vectors), implementing movemask+permute lookup (256 entries), popcount and branchless writes to produce left/right counts. Adds pointer-cast fixes, loop unrolling, cache-line alignment by over-reading, and a vectorized bitonic sort for 8-wide vectors for small runs. Benchmarks show an initial 2.7x win over CoreCLR C++ and a tuned end-to-end result near 9x faster on 1M integers, so the implementation succeeds.
AI-written summary · about
chapters (34)
- 0:00Introduction
- 2:00Singlethreaded performance improvement
- 3:05Jim Keller
- 7:30Why intrinsics
- 8:50Vectorization
- 9:40Sorting
- 11:05Why quicksort
- 12:40Quicksort basics
- 15:12Quicksort numbers
- 15:50Vectorize intrinsics
- 16:20New primitive types
- 17:20Vectorize registers
- 21:53Masks
- 22:06Looping
- 22:48Permutation table
- 29:11Stack allocation
- 33:38Whats next
- 34:42Local variables
- 36:21Fatih
- 40:47Data dependent
- 41:59Arithmetic optimum optimization
- 44:15Poormans see move
- 45:16Simpler solution
- 46:34Branch misprediction
- 47:03The remainder problem
- 48:33Cache line boundaries
- 50:45Our situation
- 51:35Partitions
- 52:00Partitioning
- 54:08Optimization
- 54:49Hybrid Sorting
- 55:41Tonic Sort
- 59:15Speedup
- 59:47Summary
related talks
58m.NET Core Internals and Optimizations
56mState of the .NET Performance
47mUnlocking Performance Improvements in .NET
52mSIMD in .NET: Image Processing with Intrinsics
27mC# as a system language
52mPerformance features in C#
56mSpeedrun Into Massive Data: Using SIMD in C#
59mPerformance tricks I learned from contributing to open source .NET packages
