Skip to content

Performance regression of ~+50% in LINQ(?) in .NET 10 compared to .NET 9 #117717

@martincostello

Description

@martincostello

Description

I've been doing various testing with previews of .NET 10 and have noticed a regression of ~+50% in a benchmark I have.

This appears to have been introduced in .NET 10 preview 5, but I only just noticed it when reviewing the results after updating to .NET 10 preview 6.

The benchmark is of a solution to an Advent of Code puzzle. Based on what the code does (Max(), Min(), First()), I think the regression is in LINQ, but I haven't drilled into exactly where the time is being spent yet.

The runtime performance of the code was significantly improved when updated from .NET 8 to .NET 9, but this improvement has noticeably regressed with .NET 10 since preview 5:

Image

Running a distillation of the original code into a dedicated benchmark gives me the following results:

BenchmarkDotNet v0.15.2, Windows 11 (10.0.26100.4652/24H2/2024Update/HudsonValley)
13th Gen Intel Core i7-13700H 2.90GHz, 1 CPU, 20 logical and 14 physical cores
.NET SDK 10.0.100-preview.6.25358.103
  [Host]     : .NET 8.0.18 (8.0.1825.31117), X64 RyuJIT AVX2
  Job-HFWDAV : .NET 10.0.0 (10.0.25.35903), X64 RyuJIT AVX2
  Job-XMDLXS : .NET 8.0.18 (8.0.1825.31117), X64 RyuJIT AVX2
  Job-NFJGQR : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
Method Runtime Mean Error StdDev Ratio Gen0 Gen1 Allocated Alloc Ratio
Solve .NET 8.0 2.918 ms 0.0351 ms 0.0293 ms 1.00 46.8750 11.7188 600.94 KB 1.00
Solve .NET 9.0 1.139 ms 0.0127 ms 0.0113 ms 0.39 44.9219 11.7188 562.14 KB 0.94
Solve .NET 10.0 1.775 ms 0.0065 ms 0.0058 ms 0.61 44.9219 11.7188 562.14 KB 0.94

I'll freely admit that the absolute performance of the solution to the puzzle could no doubt be improved, but I would expect the relative performance to remain the same or improve.

It may be that the performance regression is the result of an intentional change to improve other use cases and this is just an outlier that has to pay the price, but I thought I would raise it anyway.

Reproduction Steps

  1. Clone https://github.com/martincostello/dotnet-10-performance-regression.git
  2. Run the following commands from the root of the repository:
    $env:PUZZLE_INPUT = Resolve-Path (Join-Path "." "input.txt")
    dotnet run --configuration Release --framework net8.0 --runtimes net8.0 net9.0 net10.0

Expected behavior

Runtime performance is equivalent to .NET 9.

Actual behavior

Runtime performance is ~150% that of .NET 9.

Regression?

Yes

Known Workarounds

None

Configuration

.NET SDK 10.0.100-preview.6.25358.103

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions