Skip to content

Conversation

@ylpoonlg
Copy link

@ylpoonlg ylpoonlg commented Nov 5, 2025

The main loop body was calling GetIndexOfFirstNonAsciiByteInLane_AdvSimd to calculate the index of the non-ASCII character within the vector on every iteration, but the index is only needed when we have found a non-ASCII character. Instead, we can use VectorContainsNonAsciiChar for the checks in the loop, which is much cheaper.

Performance results

A simple benchmark is created to directly measure GetIndexOfFirstNonAsciiByte, with different buffer sizes and positions of the first non-ASCII character.

Run on Neoverse-V2 (lower is better)

Method Size NonAscii Version Mean Error Ratio
GetNonAscii 10 Middle Before 1.970 us 0.5263 us 1.000
GetNonAscii 10 Middle After 1.182 us 0.0783 us 0.600
GetNonAscii 10 None Before 1.903 us 0.4852 us 1.000
GetNonAscii 10 None After 1.216 us 0.0420 us 0.639
GetNonAscii 10 Start Before 1.894 us 0.4932 us 1.000
GetNonAscii 10 Start After 1.190 us 0.0794 us 0.628
GetNonAscii 100 Middle Before 5.881 us 0.1196 us 1.000
GetNonAscii 100 Middle After 3.226 us 0.0100 us 0.549
GetNonAscii 100 None Before 7.085 us 0.2668 us 1.000
GetNonAscii 100 None After 3.062 us 0.0550 us 0.432
GetNonAscii 100 Start Before 1.863 us 0.2965 us 1.000
GetNonAscii 100 Start After 1.535 us 0.0214 us 0.824
GetNonAscii 10000 Middle Before 250.345 us 2.6488 us 1.000
GetNonAscii 10000 Middle After 96.068 us 1.8411 us 0.384
GetNonAscii 10000 None Before 463.014 us 6.9630 us 1.000
GetNonAscii 10000 None After 199.708 us 0.8972 us 0.431
GetNonAscii 10000 Start Before 1.990 us 0.2821 us 1.000
GetNonAscii 10000 Start After 1.561 us 0.0709 us 0.784

cc @dotnet/arm64-contrib @SwapnilGaikwad

Use VectorContainsNonAsciiChar for the checks, only calculate the index
if non-ASCII character is found in the vector.
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 5, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 5, 2025
@SwapnilGaikwad
Copy link
Contributor

SwapnilGaikwad commented Nov 5, 2025

cc: @EgorBo @a74nh @JulieLeeMSFT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants