- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
Closed
Labels
Milestone
Description
Description
I've seeing massive performance regression when targeting .NET 10 instead of .NET 9 with below repro code
using System.Diagnostics;
namespace ConsoleApp17
{
    internal class Program
    {
        struct Foo
        {
            public int Value;
        }
        static long counter;
        static void Main(string[] args)
        {
            var startTime = Stopwatch.StartNew();
            var fakeData = Enumerable.Range(0, 4200000).Select(i => new Foo { Value = i });
            int outputEntriesPerBlock = 157;
            for (var i = 0; i < 26000; i++)
            {
                var blockEntries = fakeData.Skip(i * outputEntriesPerBlock).Take(outputEntriesPerBlock).ToArray();
                for (var j = 0; j < blockEntries.Length; j++)
                {
                    DoSomething(blockEntries[j]);
                }
            }
            Console.WriteLine($"Work took {startTime.Elapsed}, result {counter}");
        }
        static void DoSomething(Foo foo)
        {
            counter += foo.Value;
        }
    }
}https://github.com/wowdev/TACTSharp/blob/ed6fb1b7bd3220afea1c3845c2dbe797f553ac1c/TACTSharp/GroupIndex.cs#L93-L111 code where that problem was found initially
Project file
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net9.0;net10.0</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
  </PropertyGroup>
</Project>
Please note that PublishAot bit in a project is important because it apparently turns on UseSizeOptimizedLinq option.
Configuration
Win11 x64, .NET 10 Preview 3
Regression?
Yes.
Data
On my system i'm getting following results:
// .NET 10 
Work took 00:03:45.9408366, result 8331359959000
// .NET 9 or on .NET 10 with <UseSizeOptimizedLinq>false</UseSizeOptimizedLinq> 
Work took 00:00:00.0924906, result 8331359959000
So it's around 2443 times slower on .NET 10.
Analysis
Enabled UseSizeOptimizedLinq option (triggered by enabling PublishAot) seems to be what contributes to the problem.
Marlamin, elgonzo, TickThunder, rampaa and Balkoth
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status