Use span.Min/Max helpers to speed up SearchValues.Create#129809
Conversation
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
…y to out params Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/area-system-memory |
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);
} |
There was a problem hiding this comment.
Pull request overview
This PR replaces manual min/max loops with ReadOnlySpan<T>.Min() / .Max() calls (from MemoryExtensions.MinMax) in two places, aiming to streamline and potentially speed up min/max computation used during SearchValues.Create range detection.
Changes:
- Update
SearchValues.TryGetSingleRange<T>to computeminInclusive/maxInclusivevia spanMin()/Max()and drop theIMinMaxValue<T>constraint. - Update regex
BDD.SerializeToBytes(debug-only serializer) to validate positivity viaMin()and compute the maximum viaMax().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/BDD.cs | Switches debug-only serialization min/max computation to span Min()/Max() helpers. |
| src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs | Uses span Min()/Max() in TryGetSingleRange and removes IMinMaxValue<T> constraint. |
Copilot Code ReviewHolistic AssessmentMotivation: Justified. The PR replaces manual scalar min/max loops with the built-in vectorized Approach: Correct and minimal. The refactoring uses existing, well-tested APIs ( Summary: ✅ LGTM. Both changes are semantically equivalent to the original code, callers guarantee non-empty spans (so no Detailed FindingsDetailed Findings✅ Correctness — Empty span safety verifiedBoth call sites of
So ✅ Correctness — BDD.cs behavioral equivalenceThe old code initialized ✅ Constraint relaxation — Safe for private methodRemoving ✅ Performance path — Vectorized implementations confirmedFor the types used at call sites ( Note This review was created by GitHub Copilot.
|
Not quite as good as #124667, but that makes sense since we're doing two passes for Min/Max instead |
No description provided.