Uh oh!
There was an error while loading. Please reload this page.
Vectorize SearchValues.Create min/max scan using Vector128#124667
Conversation
Tagging subscribers to this area: @dotnet/area-system-buffers |
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
MihaZupan
commented
Feb 20, 2026
@copilot Use the benchmark skill to check the performance difference of |
@EgorBot -linux_amd -osx_arm64 usingSystem.Buffers;usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;BenchmarkSwitcher.FromAssembly(typeof(Bench).Assembly).Run(args);publicclassBench{// Standard Base64 alphabet (64 chars)privateconststringBase64Chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";[Benchmark]publicSearchValues<char>Create_Base64Alphabet()=>SearchValues.Create(Base64Chars);} |
danmoseley
commented
Feb 23, 2026
EgorBot Benchmark AnalysisLinux AMD64 — AMD EPYC 9V74 (Genoa)
macOS ARM64 — Apple M1
Summary: The vectorized |
SearchValues.Createwalks input values to find min/max (used to select the optimal search implementation) using a scalar loop. This vectorizes that scan to process multiple elements per iteration.Description
SearchValues.cs— vectorizedTryGetSingleRangeAdded a
GetMinMax<T>helper that computes min and max in a single vectorized pass:Vector128.Min/Vector128.Maxto processVector128<T>.Countelements per iteration (8ushorts or 16bytes at once)charis not a validVector128element type — the span is cast toReadOnlySpan<ushort>, and the results are converted back withUnsafe.BitCast<ushort, T>Testing
Performance was validated using @EgorBot on Linux/AMD64 and macOS/ARM64 with
SearchValues.Createon the 64-character Base64 alphabet as the benchmark input.Risk
Low —
GetMinMaxis only called duringSearchValues.Create, not on hot search paths. The scalar fallback is identical to the original code.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.