Requirements: HTTP now adds a Brotli compression algorithm to test Gzip and Brotli algorithms. Depending on the project, only the speed of decompression is tested in the article.
Brotli has12 levels of compression, from 0 to 11, where 0 provides the fastest compression speed but the lowest compression ratio, while 11 provides the highest compression ratio but requires more computing resources and time. When we first implemented Brotli 5 years ago, we determined that 4-level compression provided a balance of byte savings and compression time without compromising performance. The higher the compression level, the smaller the footprint, but it sells more CPU and memory resources.
ASP.NET Brotli algorithm is already built into the core and does not require reference to third-party packages. (This article will refer to the third-party package: BrotliSharpLib and the built-in one for comparison), the configuration is as follows:
ASP.NET Core Brotli compression call flow: ResponseCompressionServicesExtensions -> AddResponseCompression -> ResponseCompressionProvider -> BrotliCompressionProvider -> BrotliStream.
The compression level enumeration code is as follows:
Create a new .NET 6 console project with the following benchmark code:
The test results are as follows:
I tested a 503kb file, and after compression, there was not much difference, all around 400kb, and it turned out that Gzip's decompression speed was still faster than Brotli's, which should be the samefile size, . NET version, compression level, file content, etcIn short, it is best to choose the scene that suits you.
If you encounter an error like this:
Environment Summary -> Detected error exit code from one of the benchmarks. It might be caused by following antivirus software: - 360 SafeGuard (C:\Program Files (x86)\360\360Safe\safemon\360tray.exe) - Windows Defender (windowsdefender://) Use InProcessEmitToolchain or InProcessNoEmitToolchain to avoid new process creation. solution
or
(End)
|