Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does an empty method report allocating bytes? #2402

Closed
dqwork opened this issue Aug 15, 2023 · 2 comments
Closed

Why does an empty method report allocating bytes? #2402

dqwork opened this issue Aug 15, 2023 · 2 comments

Comments

@dqwork
Copy link

dqwork commented Aug 15, 2023

Hello,

I noticed some weird results from our benchmarks when we moved our app from .net framework to .net 6.0.

Methods that should not allocate at all were reporting allocations of 8 bytes.

I've investigated and in trying to make a nice simple reproducible example I discovered that an empty method reports allocating 8 bytes

// * Summary *

BenchmarkDotNet v0.13.7, Windows 10 (10.0.19045.3208/22H2/2022Update)
12th Gen Intel Core i7-1265U, 1 CPU, 12 logical and 10 physical cores
.NET SDK 7.0.400
  [Host]     : .NET 6.0.21 (6.0.2123.36311), X64 RyuJIT AVX2
  Job-NXFHSY : .NET 6.0.21 (6.0.2123.36311), X64 RyuJIT AVX2

Runtime=.NET 6.0  InvocationCount=64  IterationCount=10
LaunchCount=1  WarmupCount=8

|      Method |   Mean |  Error | StdErr | StdDev |    Min |     Q1 | Median |     Q3 |    Max |     Op/s | Rank | Allocated |
|------------ |-------:|-------:|-------:|-------:|-------:|-------:|-------:|-------:|-------:|---------:|-----:|----------:|
| EmptyMethod | 0.0 ns | 0.0 ns | 0.0 ns | 0.0 ns | 0.0 ns | 0.0 ns | 0.0 ns | 0.0 ns | 0.0 ns | Infinity |    1 |       8 B |

I've include the very basic set up I have below

Class Library defining the benchmarks - Target framework net6.0, single class

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;

namespace BenchmarkTests
{
    [MemoryDiagnoser]
    [Config(typeof(Config))]
    [RankColumn]
    [AllStatisticsColumn]
    public class Benchmarks
    {

        [Benchmark]
        public void EmptyMethod()
        {

        }


        private class Config : ManualConfig
        {
            public Config()
            {
                AddJob(
                    new Job(EnvironmentMode.Default, RunMode.Short)
                    {
                        Environment = { Runtime = CoreRuntime.Core60 },
                        Run = { InvocationCount = 64, WarmupCount = 8, IterationCount = 10 }
                    });
            }
        }
    }
}

Console App that runs the benchmarks - Target framework net6.0, single class to define entry point

using BenchmarkDotNet.Running;

namespace BenchmarkTests.Runner
{
    internal class Program
    {
        static void Main(string[] args)
        { 
            BenchmarkRunner.Run<Benchmarks>();
        }
    }
}
@timcassell
Copy link
Collaborator

It's an issue in the runtime. See #1542 and #1543.

@timcassell timcassell closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2023
@dqwork
Copy link
Author

dqwork commented Aug 15, 2023

Thank you for the quick reply

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

No branches or pull requests

2 participants