Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim some HttpHeader parsing logic on browser-wasm #52572

Closed
wants to merge 1 commit into from

Conversation

eerhardt
Copy link
Member

Introduce a new feature switch: System.Net.Http.MinimalHeaderValidation. When set to true, this switch will allow for trimming header parsing logic that may not be needed in the app.

Contributes to #44534

Before: 2,644,974 bytes
After: 2,640,488 bytes (with new feature switch set)

So roughly 4.5KB .br compressed savings in a Blazor WASM app. Opening this PR as "draft" to get feedback on the approach. I'm not convinced this savings is worth the tradeoff. Can anyone think of more header parsers that could be removed with the proposed feature switch?

cc @CoffeeFlux @marek-safar

Introduce a new feature switch: System.Net.Http.MinimalHeaderValidation. When set to `true`, this switch will allow for trimming header parsing logic that may not be needed in the app.

Contributes to dotnet#44534
@ghost
Copy link

ghost commented May 10, 2021

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

Issue Details

Introduce a new feature switch: System.Net.Http.MinimalHeaderValidation. When set to true, this switch will allow for trimming header parsing logic that may not be needed in the app.

Contributes to #44534

Before: 2,644,974 bytes
After: 2,640,488 bytes (with new feature switch set)

So roughly 4.5KB .br compressed savings in a Blazor WASM app. Opening this PR as "draft" to get feedback on the approach. I'm not convinced this savings is worth the tradeoff. Can anyone think of more header parsers that could be removed with the proposed feature switch?

cc @CoffeeFlux @marek-safar

Author: eerhardt
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

@marek-safar
Copy link
Contributor

Are parsers like DateHeaderParser excluded already?

@eerhardt
Copy link
Member Author

Are parsers like DateHeaderParser excluded already?

No. From what I can tell from the code, we won't be able to exclude parsers like that without a re-design of how the KnownHeaders work. The reason being that there is public API that rely on the parsers being there, and exceptions occur if they aren't.

For example, take the Date header:

public static readonly KnownHeader Date = new KnownHeader("Date", HttpHeaderType.General | HttpHeaderType.NonTrailing, DateHeaderParser.Parser, null, H2StaticTable.Date, H3StaticTable.Date);

There is a public HttpResponseMessage.Headers.Date property, which relies on the KnownHeaders.Date.Descriptor.Parser:

public DateTimeOffset? Date
{
get { return HeaderUtilities.GetDateTimeOffsetValue(KnownHeaders.Date.Descriptor, _parent); }
set { _parent.SetOrRemoveParsedValue(KnownHeaders.Date.Descriptor, value); }
}

If I try to exclude the DateHeaderParser from the KnownHeaders.Date entry, I get the following exception when using the Headers.Date public property:

Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.DateTimeOffset'.
   at System.Net.Http.Headers.HeaderUtilities.GetDateTimeOffsetValue(HeaderDescriptor descriptor, HttpHeaders store, Nullable`1 defaultValue) in C:\git\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\HeaderUtilities.cs:line 298
   at System.Net.Http.Headers.HttpGeneralHeaders.get_Date() in C:\git\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\HttpGeneralHeaders.cs:line 85
   at System.Net.Http.Headers.HttpResponseHeaders.get_Date() in C:\git\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\HttpResponseHeaders.cs:line 99

@geoffkizer
Copy link
Contributor

How much of the win here is MailAddressParser vs AltSvcHeaderParser?

The AltSvcHeaderParser is strictly internal, so there's no issue really with just disabling it for Blazor. @scalablecory any concerns here?

As I mentioned in the linked issue, we should strongly consider just removing MailAddressParser entirely.

@scalablecory
Copy link
Contributor

Agree AltSvc is only for SocketsHttpHandler and can be removed from browser build.

@geoffkizer
Copy link
Contributor

#52664

@geoffkizer
Copy link
Contributor

Agree AltSvc is only for SocketsHttpHandler and can be removed from browser build.

And to be clear, we don't need to introduce a feature switch to do this.

@eerhardt
Copy link
Member Author

How much of the win here is MailAddressParser vs AltSvcHeaderParser?

It's pretty much 50/50 from my measurements. MailAddressParser ~2KB compressed. AltSvcHeaderParser ~2KB compressed.

@eerhardt
Copy link
Member Author

Closing in favor of #52681 and #52794.

@eerhardt eerhardt closed this May 14, 2021
@eerhardt eerhardt deleted the HeaderValidationFeatureSwitch branch May 14, 2021 22:54
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2021
Sign up for free to 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.

5 participants