Switch all benchmark runners from BenchmarkSwitcher.Run to RunAsync#5227
Open
DrewScoggins wants to merge 3 commits into
Open
Switch all benchmark runners from BenchmarkSwitcher.Run to RunAsync#5227DrewScoggins wants to merge 3 commits into
DrewScoggins wants to merge 3 commits into
Conversation
BDN 0.16's sync entrypoints install BenchmarkDotNetSynchronizationContext (a single-threaded message pump) before benchmark discovery. Any code that does sync-over-async (e.g. ML.NET internals, SslStream handshakes) deadlocks against that pump. The async entrypoint avoids this by not installing the SyncCtx on the caller thread. This applies the same fix that was already made to MicroBenchmarks in c14e7c4 to all remaining real-world benchmark runners: - Akade.IndexedSet.Benchmarks - bepuphysics2 - ILLink - ImageSharp - Microsoft.ML.Benchmarks - PowerShell.Benchmarks - Roslyn Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
LoopedBard3
previously approved these changes
May 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the real-world benchmark runner entrypoints to use BenchmarkDotNet’s async runner APIs to avoid deadlocks caused by BenchmarkDotNetSynchronizationContext being installed by the sync entrypoints during benchmark discovery.
Changes:
- Switched multiple real-world benchmark runners from
BenchmarkSwitcher.Run(...)toRunAsync(...). - Updated entrypoints to
async(includingTask<int>where exit codes are already propagated viaToExitCode()). - Added explanatory comments about avoiding the single-threaded BDN synchronization context.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/benchmarks/real-world/Roslyn/Program.cs | Switches Roslyn runner to RunAsync and preserves exit-code behavior via ToExitCode(). |
| src/benchmarks/real-world/PowerShell.Benchmarks/Program.cs | Switches to RunAsync with async Task<int> Main and preserves exit-code behavior. |
| src/benchmarks/real-world/Microsoft.ML.Benchmarks/Program.cs | Switches to RunAsync with async Task<int> Main and preserves exit-code behavior. |
| src/benchmarks/real-world/ImageSharp/Program.cs | Switches to RunAsync with async Task Main; currently does not propagate failure exit codes. |
| src/benchmarks/real-world/ILLink/Program.cs | Switches to RunAsync with async Task<int> Main and preserves exit-code behavior. |
| src/benchmarks/real-world/bepuphysics2/Program.cs | Switches to RunAsync with async Task Main; currently does not propagate failure exit codes. |
| src/benchmarks/real-world/Akade.IndexedSet.Benchmarks/Program.cs | Switches to RunAsync via top-level await; currently does not propagate failure exit codes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
+11
| await BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).RunAsync(args, RecommendedConfig.Create( | ||
| artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location)!, "BenchmarkDotNet.Artifacts")), | ||
| mandatoryCategories: ImmutableHashSet.Create(Categories.AkadeIndexedSet))); No newline at end of file | ||
| mandatoryCategories: ImmutableHashSet.Create(Categories.AkadeIndexedSet))) | ||
| .ConfigureAwait(false); No newline at end of file |
Comment on lines
+22
to
+29
| public static async Task Main(string[] args) | ||
| { | ||
| await BenchmarkSwitcher | ||
| .FromAssembly(typeof(Program).Assembly) | ||
| .RunAsync(args, RecommendedConfig.Create( | ||
| artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BenchmarkDotNet.Artifacts")), | ||
| mandatoryCategories: ImmutableHashSet.Create(Categories.ImageSharp))) | ||
| .ConfigureAwait(false); |
Comment on lines
+12
to
+19
| public static async Task Main(string[] args) | ||
| { | ||
| await BenchmarkSwitcher | ||
| .FromAssembly(typeof(BepuPhysics2Benchmarks).Assembly) | ||
| .Run(args, RecommendedConfig.Create( | ||
| .RunAsync(args, RecommendedConfig.Create( | ||
| artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(BepuPhysics2Benchmarks).Assembly.Location), "BenchmarkDotNet.Artifacts")), | ||
| mandatoryCategories: ImmutableHashSet.Create(Categories.BepuPhysics))) | ||
| .ToExitCode(); | ||
| .ConfigureAwait(false); |
Capture the summaries returned by BenchmarkSwitcher.RunAsync and return summaries.ToExitCode() so CI can detect benchmark failures and critical validation errors via a non-zero process exit code. Addresses Copilot review comments on PR #5227. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Open
3 tasks
BDN 0.16 installs BenchmarkDotNetSynchronizationContext in the child process that executes each benchmark. ML.NET's ApplyWordEmbedding downloads a pretrained model using sync-over-async I/O internally, which deadlocks on the single-threaded SyncCtx. Save and clear the SynchronizationContext before the ML.NET pipeline code and restore it afterward, so the async download can complete without deadlocking. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BDN 0.16's sync entrypoints install BenchmarkDotNetSynchronizationContext (a single-threaded message pump) before benchmark discovery. Any code that does sync-over-async (e.g. ML.NET internals, SslStream handshakes) deadlocks against that pump. The async entrypoint avoids this by not installing the SyncCtx on the caller thread.
This applies the same fix that was already made to MicroBenchmarks in c14e7c4 to all remaining real-world benchmark runners: