Add CompressionLevel.SmallestSize and actual Gzip/Brotli compression levels (#31722)

* Document CompressionLevel.SmallestSize and actual Gzip/Brotli compression levels

Since [.Net 6](7d527c3368) there has been an additional option: `CompressionLevel.SmallestSize`. And since .Net 7 `Optimal` was [fixed](f281393412) to not mean smallest size anymore but rather a balanced value.

This change is also documents what these abstracted `CompressionLevel` values means for Gzip and Brotli compression libraries, given those are enabled by default. In my case I came to this page wanting to get an Idea of balancing CPU use vs size of the response, as there are plenty of pages online benchmarking zlib vs brotli at all possible levels and cpu types.

* Update aspnetcore/performance/response-compression.md

* Update aspnetcore/performance/response-compression.md

Co-authored-by: Tom Dykstra <tdykstra@microsoft.com>

* Update aspnetcore/performance/response-compression.md

---------

Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
Co-authored-by: Tom Dykstra <tdykstra@microsoft.com>
pull/31835/head
André R 2024-02-15 05:23:15 +01:00 committed by GitHub
parent af011a27bf
commit de3a5b9a03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 5 deletions

View File

@ -125,11 +125,7 @@ The following code:
Set the compression level with <xref:Microsoft.AspNetCore.ResponseCompression.BrotliCompressionProviderOptions> and <xref:Microsoft.AspNetCore.ResponseCompression.GzipCompressionProviderOptions>. The Brotli and Gzip compression providers default to the fastest compression level, [CompressionLevel.Fastest](xref:System.IO.Compression.CompressionLevel), which might not produce the most efficient compression. If the most efficient compression is desired, configure the response compression middleware for optimal compression.
| Compression Level | Description |
| ----------------- | ----------- |
| [CompressionLevel.Fastest](xref:System.IO.Compression.CompressionLevel) | Compression should complete as quickly as possible, even if the resulting output isn't optimally compressed. |
| [CompressionLevel.NoCompression](xref:System.IO.Compression.CompressionLevel) | No compression should be performed. |
| [CompressionLevel.Optimal](xref:System.IO.Compression.CompressionLevel) | Responses should be optimally compressed, even if the compression takes more time to complete. |
See [CompressionLevel Enum](/dotnet/api/system.io.compression.compressionlevel) for values that indicate whether a compression operation emphasizes speed or compression size.
[!code-csharp[](response-compression/samples/6.x/SampleApp/Program.cs?name=snippet2&highlight=13-21)]