-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Trimming Http in Blazor wasm #44534
Comments
Tagging subscribers to this area: @dotnet/ncl Issue meta data
|
The vast majority of that code is around header validation, e.g. when you set HttpRequestHeaders.From on a message, it validating that it's a well-formed email address. I think the flag here will basically need to be "I don't care about header validation at the HttpClient layer", at which point I'd expect a significant portion of the header logic could be trimmable away. Alternatively, we could simply say that for the Blazor wasm build we don't layer on much special validation, and simply have a different implementation that effectively ifdefs away all of that code. More specifically, much of it ends up being kept because of the parsers defined in the known headers here: cc: @geoffkizer |
@geoffkizer @wfurt @scalablecory @dotnet/ncl - anyone have any thoughts on the above? Would either of these approaches be acceptable in |
We can't rip out the header parsers/validators in general without removing strongly typed header properties as well, which I assume we don't want to do.... Is there a way to see details on what methods account for what space, etc? |
You can use the following steps to trim a default Blazor WASM app:
When I do this, here is what is left: Analyze these classes and decide whether each is completely necessary in a |
The HPACK and QPACK stuff is HTTP2/3 specific and could be removed, though I expect there's some trickiness with the KnownHeaders stuff that makes this a bit painful. I don't know what TaskToApm is used for; we could investigate this but I doubt it's much code. As for the rest, I don't see much that can be removed, unfortunately. |
I was thinking we could consider weakening the validation. For example, there's a ton of code purely to validate that From headers are properly formatted as email addresses. Do we need all of that for wasm? |
Maybe not. To what extent do we care about behavioral differences here? Alternatively, to what extent do we really care about validation of From headers even in non-wasm scenarios? |
Personally? Very little 😉 Just for context, changing: runtime/src/libraries/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs Line 50 in 6578f25
to pass null as the parser, and deleting this line: runtime/src/libraries/System.Net.Http/src/System/Net/Http/Headers/GenericHeaderParser.cs Line 21 in 6578f25
shrinks the size of System.Net.Http.dll in the default blazor wasm template by 7K uncompressed and 2K compressed. |
This allows for HPackEncoder and QPackEncoder to be trimmed in browser wasm. Contributes to dotnet#44534
* Remove the HTTP2 and HTTP3 implementations on browser-wasm. This allows for HPackEncoder and QPackEncoder to be trimmed in browser wasm. Contributes to #44534
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
I opened #52572 for @stephentoub's proposal above, in case anyone is interested in taking a look. After that idea and #52420, I'm not seeing much more than can be trimmed from |
Contributes to dotnet#44534
System.Net.Http is one of the largest libraries in the Blazor sample, taking up 53KB when compressed with Brotli. Most of this space is held in the headers, most of which are not likely to be used. We should investigate some sort of feature flag here to try and get rid of this even if the linker cannot guarantee it will be unused.
The size grew also when http2 and http3 support was added for SocketHttpHandler which is not used and excluded for Browser and still the various caches and static data are populated.
The text was updated successfully, but these errors were encountered: