Open performanceautofiler[bot] opened 2 years ago
Tagging subscribers to this area: @dotnet/area-system-io-compression See info in area-owners.md if you want to be subscribed.
Author: | performanceautofiler[bot] |
---|---|
Assignees: | DrewScoggins |
Labels: | `area-System.IO.Compression`, `Regression` |
Milestone: | - |
https://github.com/dotnet/runtime/pull/72266 @stephentoub
This is a perf test bug. cc: @adamsitnik
The test is assuming that all work associated with a write happens during the write: https://github.com/dotnet/performance/blob/e03024567eb5b6c66e51751c08f0ae1f7f3d3059/src/benchmarks/micro/libraries/System.IO.Compression/CompressionStreamPerfTestBase.cs#L57-L64 That isn't the case. In fact, the higher the compression algorithm, the larger the internal buffer will be used by Brotli, which means at the highest level of compression, the buffer is so large that basically no work happens in the Write call other than copying the data over to the native buffer. And since the stream is never being disposed, the bulk of the work isn't actually happening, and so the test isn't actually measuring what it's supposed to be measuring.
With the test as is, when I run it locally I get similarly terrible-looking results:
Method | Runtime | level | file | Mean | Ratio |
---|---|---|---|---|---|
Compress | .NET 6.0 | Optimal | TestDocument.pdf | 15.755 us | 1.00 |
Compress | .NET 7.0 | Optimal | TestDocument.pdf | 467.284 us | 29.89 |
Compress | .NET 6.0 | Optimal | alice29.txt | 35.456 us | 1.00 |
Compress | .NET 7.0 | Optimal | alice29.txt | 2,202.550 us | 62.20 |
But, when I fix the test, by changing: https://github.com/dotnet/performance/blob/e03024567eb5b6c66e51751c08f0ae1f7f3d3059/src/benchmarks/micro/libraries/System.IO.Compression/CompressionStreamPerfTestBase.cs#L62
var compressor = CreateStream(CompressedFile.CompressedDataStream, level);
to instead be:
using var compressor = CreateStream(CompressedFile.CompressedDataStream, level);
public override Stream CreateStream(Stream stream, CompressionLevel level) => new BrotliStream(stream, level);
to instead be:
public override Stream CreateStream(Stream stream, CompressionLevel level) => new BrotliStream(stream, level, leaveOpen: true);
I then get these results:
Method | Runtime | level | file | Mean | Ratio |
---|---|---|---|---|---|
Compress | .NET 6.0 | Optimal | TestDocument.pdf | 457,331.4 us | 1.000 |
Compress | .NET 7.0 | Optimal | TestDocument.pdf | 1,145.6 us | 0.003 |
Compress | .NET 6.0 | Optimal | alice29.txt | 203,330.7 us | 1.00 |
Compress | .NET 7.0 | Optimal | alice29.txt | 3,024.0 us | 0.02 |
which is way more in line with the expected result of my PR.
Run Information
Regressions in System.IO.Compression.Brotli
Test Report
Repro