diff --git a/src/BenchmarkDotNet/Engines/Engine.cs b/src/BenchmarkDotNet/Engines/Engine.cs index 567125dfdf..7cfb8e90fb 100644 --- a/src/BenchmarkDotNet/Engines/Engine.cs +++ b/src/BenchmarkDotNet/Engines/Engine.cs @@ -1,4 +1,4 @@ -using BenchmarkDotNet.Attributes.CompilerServices; +using BenchmarkDotNet.Attributes.CompilerServices; using BenchmarkDotNet.Characteristics; using BenchmarkDotNet.Helpers; using BenchmarkDotNet.Jobs; @@ -89,16 +89,19 @@ public async ValueTask RunAsync() } // This method is extra long because the helper methods were inlined in order to prevent extra async allocations on each iteration. - private async ValueTask RunCore() + private async Task RunCore() { + // We need to force an async yield here to ensure each benchmark invocation is called with a constant stack size. #1120 + await Task.Yield(); + Host.CancellationToken.ThrowIfCancellationRequested(); + var measurements = new List(); if (EngineEventSource.Log.IsEnabled()) EngineEventSource.Log.BenchmarkStart(Parameters.BenchmarkName); IterationData extraIterationData = default; - // Enumerate the stages and run iterations in a loop to ensure each benchmark invocation is called with a constant stack size. - // #1120 + // Enumerate the stages and run iterations in a loop to ensure each benchmark invocation is called with a constant stack size. #1120 foreach (var stage in EngineStage.EnumerateStages(Parameters)) { if (stage.Stage == IterationStage.Actual && stage.Mode == IterationMode.Workload) diff --git a/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/InProcessNoEmitRunner.cs b/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/InProcessNoEmitRunner.cs index b899244fbe..b5e8b75cac 100644 --- a/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/InProcessNoEmitRunner.cs +++ b/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/InProcessNoEmitRunner.cs @@ -36,7 +36,7 @@ public static async ValueTask Run(IHost host, ExecuteParameters parameters, var methodInfo = type.GetMethod(nameof(Runnable.RunCore), BindingFlags.Public | BindingFlags.Static) ?? throw new InvalidOperationException($"Bug: method {nameof(Runnable.RunCore)} in {inProcessRunnableTypeName} not found."); - await ((ValueTask) methodInfo.Invoke(null, [host, parameters, benchmarkActionFactory])!).ConfigureAwait(false); + await ((ValueTask) methodInfo.Invoke(null, [host, parameters, benchmarkActionFactory])!).ConfigureAwait(true); return 0; }