Skip to content

StackOverflow when adding empty IterationSetup method #2743

@olstakh

Description

@olstakh

Hi. I'm trying to test performance of some ILogger extensions that use a lot of lambdas.

Benchmarks has the following structure

[HtmlExporter]
[MarkdownExporter]
[MemoryDiagnoser]
[MaxColumn, MinColumn, MeanColumn]
public class LoggingBenchmark
{
    MyLogger _logger = new();

    [GlobalSetup]
    public void GlobalSetup()
    {
        _logger = new MyLogger();
    }

    // [IterationSetup]
    public void IterationSetup()
    {
    }

    [Params(1, 10, 100, 1000)]
    public int Depth { get; set; }

    [Benchmark]
    public Task<int> Logger_ExecuteAsync()
    {
        return Helper.RunRecursively_ExecuteAsync(_logger, Depth);
    }
}

The helper method is the equivalent of

Task<int> RunRecursively_ExecuteAsync(ILogger logger, int depth)
{
   return logger.ExecuteAsync(async () =>
   {
       return depth == 0 ? 42 : await RunRecursively_ExecuteAsync(logger, depth - 1);
   })
}

ExecuteAsync is just an extension that does try/catch around async action and logs some stuff

For some reason i'm getting stack overflow exception when uncommenting // [IterationSetup] attribute, even though the method is empty.
Any immediate thoughts about the difference, before i invest into making full repro? Looks a bit odd on my end

StackOverflow is obviously for the Depth = 1000 case, runs out of stack arfet 800 or so.

BenchmarkDotNet version: 0.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions