Skip to content

Use IL shuffle thunk on all platforms#131303

Closed
huoyaoyuan wants to merge 2 commits into
dotnet:mainfrom
huoyaoyuan:shuffle-thunk-il
Closed

Use IL shuffle thunk on all platforms#131303
huoyaoyuan wants to merge 2 commits into
dotnet:mainfrom
huoyaoyuan:shuffle-thunk-il

Conversation

@huoyaoyuan

Copy link
Copy Markdown
Member

Open early to see the benchmark and tests.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 24, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@huoyaoyuan

Copy link
Copy Markdown
Member Author

@EgorBot -intel -amd -arm64

using System;
using BenchmarkDotNet.Attributes;

namespace BenchmarkGround
{
    public struct GCStruct
    {
        public object a, b, c, d, e, f, h, g;
    }

    public class Bench
    {
        private readonly object obj = new object();

        private readonly Guid guid = Guid.NewGuid();

        private readonly GCStruct gcStruct = new GCStruct
        {
            a = new object(),
            g = new object()
        };

        private Action<int> singleArg = SingleArg_Static;
        public static void SingleArg_Static(int a) { }

        private Func<int, double, Guid, GCStruct, object, double> manyArg_RetFPU = ManyArg_RetFPU_Static;
        public static double ManyArg_RetFPU_Static(int a, double b, Guid c, GCStruct d, object e) => 1.0;

        [Benchmark]
        public void SingleArg() => singleArg(0);

        [Benchmark]
        public double ManyArg_RetFPU() => manyArg_RetFPU(1, 2.0, guid, gcStruct, obj);
    }
}

@huoyaoyuan

huoyaoyuan commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

The initiative is getting such unbelievable benchmark result locally:

Method Job Toolchain Mean Error StdDev Ratio
SingleArg Job-NHYPTB \PR\corerun.exe 1.250 ns 0.0073 ns 0.0068 ns 1.00
SingleArg Job-ZICBXN \main\corerun.exe 1.248 ns 0.0120 ns 0.0112 ns 1.00
ManyArg_RetFPU Job-NHYPTB \PR\corerun.exe 1.857 ns 0.0143 ns 0.0134 ns 0.02
ManyArg_RetFPU Job-ZICBXN \main\corerun.exe 92.010 ns 0.5680 ns 0.5313 ns 1.00

The 90ns result also reproduces with 10.0.10.

It only reproduces on Windows. Even for 7 args on Linux, the time is still <3ns.

@huoyaoyuan

Copy link
Copy Markdown
Member Author

@EgorBot -windows_x64 -linux_x64 -arm64

using System;
using BenchmarkDotNet.Attributes;

namespace BenchmarkGround
{
    public struct GCStruct
    {
        public object a, b, c, d, e, f, h, g;
    }

    public class Bench
    {
        private readonly object obj = new object();

        private readonly Guid guid = Guid.NewGuid();

        private readonly GCStruct gcStruct = new GCStruct
        {
            a = new object(),
            g = new object()
        };

        private Action<int> singleArg = SingleArg_Static;
        public static void SingleArg_Static(int a) { }

        private Func<int, double, Guid, GCStruct, object, double> manyArg_RetFPU = ManyArg_RetFPU_Static;
        public static double ManyArg_RetFPU_Static(int a, double b, Guid c, GCStruct d, object e) => 1.0;

        private Func<int, double, Guid, GCStruct, object, Int128, UInt128, double> moreArg_RetFPU = MoreArg_RetFPU_Static;
        public static double MoreArg_RetFPU_Static(int a, double b, Guid c, GCStruct d, object e, Int128 f, UInt128 g) => 1.0;

        [Benchmark]
        public void SingleArg() => singleArg(0);

        [Benchmark]
        public double ManyArg_RetFPU() => manyArg_RetFPU(1, 2.0, guid, gcStruct, obj);

        [Benchmark]
        public double MoreArg_RetFPU() => moreArg_RetFPU(1, 2.0, guid, gcStruct, obj, 0, 0);
    }
}

@huoyaoyuan

Copy link
Copy Markdown
Member Author

Closing as problem in both tests and performance. Still curious why the 90ns case happens on local Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant