Skip to content

Use IndexOfAnyValues in System.Net.Http - #78660

Merged
stephentoub merged 1 commit into
dotnet:mainfrom
MihaZupan:indexofanyvalues-http
Nov 22, 2022
Merged

Use IndexOfAnyValues in System.Net.Http#78660
stephentoub merged 1 commit into
dotnet:mainfrom
MihaZupan:indexofanyvalues-http

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

Contributes to #78204

Example performance numbers for HttpRuleParser.IsToken taken from #78093's description:

MethodLengthMeanError
IndexOfAnyValues_Char12.683 ns0.0108 ns
CurrentChar11.655 ns0.0046 ns
IndexOfAnyValues_Char77.184 ns0.0185 ns
CurrentChar74.989 ns0.1115 ns
IndexOfAnyValues_Char82.402 ns0.0025 ns
CurrentChar84.787 ns0.0155 ns
IndexOfAnyValues_Char162.409 ns0.0052 ns
CurrentChar169.100 ns0.0119 ns
IndexOfAnyValues_Char323.306 ns0.0078 ns
CurrentChar3219.486 ns0.5098 ns
IndexOfAnyValues_Char1000006,004.741 ns4.4187 ns
CurrentChar10000057,569.776 ns49.4496 ns
IndexOfAnyValues_Byte11.749 ns0.0058 ns
CurrentByte11.677 ns0.0243 ns
IndexOfAnyValues_Byte74.835 ns0.0779 ns
CurrentByte75.112 ns0.0038 ns
IndexOfAnyValues_Byte82.521 ns0.0046 ns
CurrentByte85.274 ns0.0052 ns
IndexOfAnyValues_Byte162.519 ns0.0021 ns
CurrentByte169.113 ns0.0166 ns
IndexOfAnyValues_Byte323.141 ns0.0023 ns
CurrentByte3219.417 ns1.0021 ns
IndexOfAnyValues_Byte1000004,762.442 ns21.2032 ns
CurrentByte10000057,967.138 ns97.4594 ns

@MihaZupanMihaZupan added this to the 8.0.0 milestone Nov 21, 2022
@MihaZupan
MihaZupan requested a review from a teamNovember 21, 2022 22:14
@ghostghost assigned MihaZupanNov 21, 2022
@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Contributes to #78204

Example performance numbers for HttpRuleParser.IsToken taken from #78093's description:

MethodLengthMeanError
IndexOfAnyValues_Char12.683 ns0.0108 ns
CurrentChar11.655 ns0.0046 ns
IndexOfAnyValues_Char77.184 ns0.0185 ns
CurrentChar74.989 ns0.1115 ns
IndexOfAnyValues_Char82.402 ns0.0025 ns
CurrentChar84.787 ns0.0155 ns
IndexOfAnyValues_Char162.409 ns0.0052 ns
CurrentChar169.100 ns0.0119 ns
IndexOfAnyValues_Char323.306 ns0.0078 ns
CurrentChar3219.486 ns0.5098 ns
IndexOfAnyValues_Char1000006,004.741 ns4.4187 ns
CurrentChar10000057,569.776 ns49.4496 ns
IndexOfAnyValues_Byte11.749 ns0.0058 ns
CurrentByte11.677 ns0.0243 ns
IndexOfAnyValues_Byte74.835 ns0.0779 ns
CurrentByte75.112 ns0.0038 ns
IndexOfAnyValues_Byte82.521 ns0.0046 ns
CurrentByte85.274 ns0.0052 ns
IndexOfAnyValues_Byte162.519 ns0.0021 ns
CurrentByte169.113 ns0.0166 ns
IndexOfAnyValues_Byte323.141 ns0.0023 ns
CurrentByte3219.417 ns1.0021 ns
IndexOfAnyValues_Byte1000004,762.442 ns21.2032 ns
CurrentByte10000057,967.138 ns97.4594 ns
Author:MihaZupan
Assignees:-
Labels:

area-System.Net.Http

Milestone:8.0.0

@MihaZupan
MihaZupan marked this pull request as ready for review November 21, 2022 22:14

@stephentoubstephentoub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@stephentoub
stephentoub merged commit aa91451 into dotnet:mainNov 22, 2022
@MihaZupan

MihaZupan commented Nov 22, 2022

Copy link
Copy Markdown
MemberAuthor

I'm seeing failures on checked builds on ARM64 machines in #78678 that are likely related to changes to Encode5987 in this PR.

System.Net.Http.Tests.ContentDispositionHeaderValueTest.FileNameStar_NeedsEncoding_EncodedAndDecodedCorrectly [FAIL]
Assert.Equal() Failure
↓ (pos 4)
Expected: FileÃName.bat
Actual: File?�Name.bat
↑ (pos 4)
Stack Trace:
/_/src/libraries/System.Net.Http/tests/UnitTests/Headers/ContentDispositionHeaderValueTest.cs(211,0): at System.Net.Http.Tests.ContentDispositionHeaderValueTest.FileNameStar_NeedsEncoding_EncodedAndDecodedCorrectly()

https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-78678-merge-3f1a8789e4f74bd6ac/System.Net.Http.Unit.Tests/3/console.0d41b14c.log?helixlogtype=result

https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-78678-merge-7f5df04042ea41ae83/System.Net.Http.Unit.Tests/3/console.17646da3.log?helixlogtype=result

cc: @EgorBo@tannergooding - this looks like different runtime behavior for Encode5987 on checked vs non-checked ARM64 builds (likely related to the new IndexOfAnyValues APIs added in #78093).

@stephentoub

Copy link
Copy Markdown
Member

It's showing up on other PRs as well.

@EgorBo

Copy link
Copy Markdown
Member

I'll see if it's due to #78630 (via #78700)

length = utf8.Length;
}

Encoding.ASCII.GetChars(utf8.Slice(0, length), builder.AppendSpan(length));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be Encoding.ASCII?

Given that the failure is on alpine I wonder if it could be some locale issue?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be affected by locale. The input here will always be these bytes (all in the [0, 127] range).

// attr-char = ALPHA / DIGIT / "!" / "#" / "$" / "&" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
// ; token except ( "*" / "'" / "%" )
privatestaticreadonlyIndexOfAnyValues<byte>s_rfc5987AttrBytes=
IndexOfAnyValues.Create("!#$&+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz|~"u8);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks. I also just noticed that there are non-alpine failures too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EgorBo

Copy link
Copy Markdown
Member

@MihaZupan no, it's not #78630 since revert still fails 🤔

@MihaZupanMihaZupan mentioned this pull request Nov 22, 2022
@MihaZupan

Copy link
Copy Markdown
MemberAuthor

Doing some tests in #78709 to try and narrow it down

@ghostghost locked as resolved and limited conversation to collaborators Dec 22, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@MihaZupan@stephentoub@EgorBo@jakobbotsch