MSDN

Benchmarking .NET 8 Garbage Collector

By Alice Johnson • September 13, 2025 • 7 min read

The .NET 8 runtime introduces several enhancements to the Garbage Collector (GC) aimed at reducing pause times and improving throughput. In this post, we walk through a series of benchmarks that compare .NET 8 GC performance against .NET 6 and .NET 7 across different workloads.

Test Environment

Workloads

ScenarioDescriptionAlloc Rate (GB/s)
JSON ParsingParse 1 M JSON blobs (≈500 KB each)2.4
Image ProcessingResize 500 k 4K images using System.Drawing1.8
In‑Memory CacheSimulate a 10 M item cache with sliding expiration3.2

Results

Analysis

Across all scenarios, .NET 8 consistently reduces GC pause time by ~15‑20 % compared to .NET 7, with the most significant gains observed in high‑allocation workloads like the in‑memory cache.

Key Improvements

  1. Enhanced Concurrent Mark algorithm reduces fragmentation.
  2. Adaptive generation sizing based on runtime heuristics.
  3. Optimized ephemeral segment handling for short‑lived objects.

Sample Code

// Benchmark for JSON parsing
var json = File.ReadAllText("sample.json");
var sw = Stopwatch.StartNew();
for (int i = 0; i < 1_000_000; i++)
{
    var obj = JsonSerializer.Deserialize<MyDto>(json);
}
Console.WriteLine($"Elapsed: {sw.Elapsed}");

Running the above snippet with dotnet run -c Release on .NET 8 yields a 12 % faster execution time compared to .NET 7 on the same hardware.