Skip to content

Possible regression with [ThreadStatic] in debug builds on .NET 9 RC1 #107728

Closed
@alexyakunin

Description

@alexyakunin

Description

One of our tests started to run ~20x slower on .NET 9 RC1, if it's compiled in Debug configuration.

That's where it spends most of its time:

image

There is another branch with similar ~38%, and it's also on the same ThreadRandom.get_Instance call.

ThreadRandom looks as follows:

public static class ThreadRandom
{
    [ThreadStatic] private static Random? _instance;

    public static Random Instance {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get => _instance ??= CreateInstance();
    }

    private static Random CreateInstance()
        => new(Random.Shared.Next());
}

What's weird is that all of my attempts to reproduce this perf. regression on isolated console app failed, even though a console app running the code of this specific unit test also manifests the regression.

Configuration

Windows 11 machine.

Regression?

Yes, it looks like this is a perf. regression.

Data

No additional data.

Analysis

Not sure what it could be.

Metadata

Metadata

Assignees

Labels

area-VM-coreclrin-prThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions