dotnet / dotnet/performance

Add compression benchmarks that capture recent zlib regressions

Open
#4,900 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
F#
Stars
773
Forks
301
Avg merge
6d 9h
Merged PRs (30d)
15

Description

## Highly compressible data
https://github.com/dotnet/runtime/pull/118457#issuecomment-3161005108 includes a comparison and sample benchmark that includes a large number of iterations of highly-compressible data. This regressed in 9.0 and was missed. We should add a benchmark to cover that.
```c#
[Benchmark]
public void CompressionTest()
{
var testData = _testData[TestFile];
testData.CompressedStream.Position = 0;

using (var z = new DeflateStream(testData.CompressedStream, CompressionMode.Compress, true))
{
for (int i = 0; i < testData.Iterations; i++)
{
z.Write(testData.Data);
}
}
}
```
https://github.com/dotnet/performance/blob/main/src/benchmarks/micro/libraries/System.IO.Compression/TestData/alice29.txt should fit the bill, so simply adding some iterations to https://github.com/dotnet/performance/blob/b8a4259b132a8460c915b4d1e04ebf47e403d151/src/benchmarks/micro/libraries/System.IO.Compression/CompressionStreamPerfTestBase.cs#L58-L64 might be enough to capture.

## Heap fragmentation
https://github.com/dotnet/runtime/pull/117949 addresses a case where removal of our custom allocator regressed performance on windows x64.

We were able to reproduce that with a benchmark that @stephentoub wrote:
```c#
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.IO.Compression;

BenchmarkSwitcher.FromAssembly(typeof(Bench).Assembly).Run(args);

public class Bench
{
private Barrier _barrier = new Barrier(Environment.ProcessorCount - 1);

[Benchmark]
public void Test()
{
Task.WaitAll(Enumerable
.Range(0, _barrier.ParticipantCount)
.Select(_ => Task.Run(() =>
{
_barrier.SignalAndWait();
for (int length = 1; length < 1000; length++)
{

byte[] buffer = new byte[length];
Random.Shared.NextBytes(buffer);
using (var z = new ZLibStream(new MemoryStream(), CompressionMode.Compress))
{
for (int i = 0; i < 100; i++)
{
z.Write(buffer);
}
}
}
})).ToArray());
}
}
```

| Method | Runtime | Mean | Error | StdDev | Ratio | RatioSD |
|------- |--------- |---------:|--------:|--------:|------:|--------:|
| Test | .NET 8.0 | 153.2 ms | 3.05 ms | 8.44 ms | 1.00 | 0.08 |
| Test | .NET 9.0 | 289.5 ms | 5.64 ms | 8.61 ms | 1.90 | 0.12 |

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.