From ba41bae04fc9bb85d2bccb6e620085cdcc287768 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Tue, 1 Sep 2026 14:00:25 +0300 Subject: [PATCH 1/2] Configure r2r to disable runtime code generation in the r2r_interpreter configuration This configuration used to be hardcoded in crossgen2, but it workaround was recently reverted with proper support added in https://github.com/dotnet/runtime/commit/5b11923ecac20a8367b4ca60a9b9739479319e9a. This means r2r_interpreter configuration needs to pass `--target-allows-runtime-code-generation:false` to crossgen. This can be achieved by having the bdn autogenerated project receive the msbuild property `PublishReadyToRunCrossgen2ExtraArgs` initialized to this extra arg. Given bdn doesn't support this configuration via its cli arguments (https://github.com/dotnet/BenchmarkDotNet/blob/master/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs), we add a new argument to the microbenchmark project --msbuild-argument, which will be forwarded to bdn via the job arguments (job.WithMsBuildArguments). --- scripts/run_performance_job.py | 4 ++++ src/benchmarks/micro/Program.cs | 5 ++++- .../BenchmarkDotNet.Extensions/RecommendedConfig.cs | 8 +++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/run_performance_job.py b/scripts/run_performance_job.py index e8026a71639..06ee77b9c43 100644 --- a/scripts/run_performance_job.py +++ b/scripts/run_performance_job.py @@ -553,6 +553,10 @@ def get_bdn_arguments( bdn_arguments += ["\\\"--wasmArgs=--experimental-wasm-exnref\\\""] if runtime_type == "coreclr_r2r_interpreter": + bdn_arguments += [ + "--msbuild-arguments", + "/p:PublishReadyToRunCrossgen2ExtraArgs=--target-allows-runtime-code-generation:false", + ] if os_group == "windows": bdn_arguments += [ "--runtimes", "r2r11_0", diff --git a/src/benchmarks/micro/Program.cs b/src/benchmarks/micro/Program.cs index 8d2a590cae9..28e9eca5312 100644 --- a/src/benchmarks/micro/Program.cs +++ b/src/benchmarks/micro/Program.cs @@ -22,6 +22,7 @@ static async Task Main(string[] args) int? partitionIndex; List exclusionFilterValue; List categoryExclusionFilterValue; + List msBuildArguments; bool getDiffableDisasm; // Parse and remove any additional parameters that we need that aren't part of BDN @@ -31,6 +32,7 @@ static async Task Main(string[] args) argsList = CommandLineOptions.ParseAndRemoveIntParameter(argsList, "--partition-index", out partitionIndex); argsList = CommandLineOptions.ParseAndRemoveStringsParameter(argsList, "--exclusion-filter", out exclusionFilterValue); argsList = CommandLineOptions.ParseAndRemoveStringsParameter(argsList, "--category-exclusion-filter", out categoryExclusionFilterValue); + argsList = CommandLineOptions.ParseAndRemoveStringsParameter(argsList, "--msbuild-arguments", out msBuildArguments); CommandLineOptions.ParseAndRemoveBooleanParameter(argsList, "--disasm-diff", out getDiffableDisasm); CommandLineOptions.ValidatePartitionParameters(partitionCount, partitionIndex); @@ -56,7 +58,8 @@ static async Task Main(string[] args) partitionIndex: partitionIndex, exclusionFilterValue: exclusionFilterValue, categoryExclusionFilterValue: categoryExclusionFilterValue, - getDiffableDisasm: getDiffableDisasm) + getDiffableDisasm: getDiffableDisasm, + msBuildArguments: msBuildArguments) .AddValidator(new NoWasmValidator(Categories.NoWASM))) .ConfigureAwait(false); diff --git a/src/harness/BenchmarkDotNet.Extensions/RecommendedConfig.cs b/src/harness/BenchmarkDotNet.Extensions/RecommendedConfig.cs index c8a469ba68e..2630289ae2c 100644 --- a/src/harness/BenchmarkDotNet.Extensions/RecommendedConfig.cs +++ b/src/harness/BenchmarkDotNet.Extensions/RecommendedConfig.cs @@ -28,7 +28,8 @@ public static IConfig Create( List? exclusionFilterValue = null, List? categoryExclusionFilterValue = null, Job? job = null, - bool getDiffableDisasm = false) + bool getDiffableDisasm = false, + IReadOnlyList? msBuildArguments = null) { if (job is null) { @@ -43,6 +44,11 @@ public static IConfig Create( #pragma warning restore CS0618 } + if (msBuildArguments is not null && msBuildArguments.Count > 0) + { + job = job.WithMsBuildArguments(msBuildArguments.ToArray()); + } + var config = ManualConfig.CreateEmpty() .WithBuildTimeout(TimeSpan.FromMinutes(15)) // for slow machines .AddLogger(ConsoleLogger.Default) // log output to console From 1d11b51daaf2d9b47accf42b3c4378c39fbb16f8 Mon Sep 17 00:00:00 2001 From: Parker Bibus Date: Wed, 16 Sep 2026 11:31:50 -0700 Subject: [PATCH 2/2] Document microbenchmark MSBuild argument syntax Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/benchmarkdotnet.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/benchmarkdotnet.md b/docs/benchmarkdotnet.md index be429f57ad7..41b6f170b39 100644 --- a/docs/benchmarkdotnet.md +++ b/docs/benchmarkdotnet.md @@ -117,6 +117,12 @@ And select one of the benchmarks from the list by either entering its number or ### Command Line +The microbenchmark `--msbuild-arguments` option passes additional arguments to MSBuild for BenchmarkDotNet's generated project. Use slash-prefixed arguments such as `/p:` or `/t:`, not `-p:` or `-t:`: `CommandLineOptions.ParseAndRemoveStringsParameter` stops collecting values at any token beginning with `-`. Embedded `--` within a `/p:` value is fine, for example: + +```text +--msbuild-arguments /p:PublishReadyToRunCrossgen2ExtraArgs=--target-allows-runtime-code-generation:false +``` + #### Filtering the Benchmarks You can filter the benchmarks using `--filter $globPattern` console line argument. The filter is **case insensitive**.