Vectorize SearchValues.Create min/max scan using Vector128#124667
Draft
Vectorize SearchValues.Create min/max scan using Vector128#124667
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-buffers |
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Vectorize min and max computation in SearchValues.Create
Vectorize SearchValues.Create min/max scan and ASCII bitmap construction
Feb 20, 2026
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Copilot
AI
changed the title
Vectorize SearchValues.Create min/max scan and ASCII bitmap construction
Vectorize SearchValues.Create min/max scan using Vector128
Feb 20, 2026
Member
|
@copilot Use the benchmark skill to check the performance difference of |
Contributor
Author
@EgorBot -linux_amd -osx_arm64 using System.Buffers;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkSwitcher.FromAssembly(typeof(Bench).Assembly).Run(args);
public class Bench
{
// Standard Base64 alphabet (64 chars)
private const string Base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
[Benchmark]
public SearchValues<char> Create_Base64Alphabet() =>
SearchValues.Create(Base64Chars);
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.