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

Allow DecompressionHandler to be trimmed when the application isn't using AutomaticDecompression in HttpClient. #78198

Merged
merged 1 commit into from Nov 11, 2022

Conversation

eerhardt
Copy link
Member

This allow for the Brotli and Deflate compression code to be trimmed in a NativeAOT app that uses HttpClient, which is about 1 MB of size savings on Linux.

The idea is to make a Delegate that will create the DecompressionHandler object. If no one calls the setter for SocketsHttpHandler.AutomaticDecompression, then the Delegate stays null and the DecompressionHandler class and its dependencies can be trimmed.

…sing AutomaticDecompression in HttpClient.

This allow for the Brotli compression code to be trimmed in a NativeAOT app that uses HttpClient, which is about 1 MB of size savings on Linux.
@eerhardt eerhardt added the size-reduction Issues impacting final app size primary for size sensitive workloads label Nov 11, 2022
@ghost ghost assigned eerhardt Nov 11, 2022
@ghost
Copy link

ghost commented Nov 11, 2022

Tagging subscribers to 'size-reduction': @eerhardt, @SamMonoRT, @marek-safar
See info in area-owners.md if you want to be subscribed.

Issue Details

This allow for the Brotli and Deflate compression code to be trimmed in a NativeAOT app that uses HttpClient, which is about 1 MB of size savings on Linux.

The idea is to make a Delegate that will create the DecompressionHandler object. If no one calls the setter for SocketsHttpHandler.AutomaticDecompression, then the Delegate stays null and the DecompressionHandler class and its dependencies can be trimmed.

Author: eerhardt
Assignees: -
Labels:

size-reduction

Milestone: -

@SamMonoRT
Copy link
Member

SamMonoRT commented Nov 11, 2022

@ivanpovazan @kotlarmilos @akoeplinger fyi

// AutomaticDecompression is not being used.
private void EnsureDecompressionHandlerFactory()
{
_decompressionHandlerFactory ??= (settings, handler) => new DecompressionHandler(settings._automaticDecompression, handler);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: just to make sure we don't accidentally create a closure

Suggested change
_decompressionHandlerFactory ??= (settings, handler) => new DecompressionHandler(settings._automaticDecompression, handler);
_decompressionHandlerFactory ??= static (settings, handler) => new DecompressionHandler(settings._automaticDecompression, handler);

@stephentoub stephentoub added this to the 8.0.0 milestone Nov 11, 2022
@stephentoub stephentoub merged commit 35bec28 into dotnet:main Nov 11, 2022
@eerhardt eerhardt deleted the TrimDecompressionHandler branch November 14, 2022 02:27
@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Http size-reduction Issues impacting final app size primary for size sensitive workloads
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants