Skip to content

refactor: enable nullable reference types in BenchmarkReport#754

Merged
vbreuss merged 2 commits into
mainfrom
topic/enable-nullable-for-benchmarkreport
May 2, 2026
Merged

refactor: enable nullable reference types in BenchmarkReport#754
vbreuss merged 2 commits into
mainfrom
topic/enable-nullable-for-benchmarkreport

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 2, 2026

This pull request refactors the Pipeline/BenchmarkReport.cs file to modernize and simplify the code, making it more idiomatic and concise. The changes focus on improving code readability, reducing redundancy, and leveraging newer C# features such as target-typed new, nullable reference types, and pattern-based null checks.

Key improvements include:

Code Modernization & Simplification

  • Replaced explicit type declarations with var where appropriate, streamlined null checks, and used target-typed new for object initialization, resulting in more concise and readable code throughout the file.

  • Replaced multi-line if statements with single-line expressions where possible, and simplified method bodies by removing unnecessary braces and lines.

Nullable Reference Types & Type Safety

  • Updated methods and parameters to use nullable reference types (e.g., string[]?) and added [NotNullWhen(true)] attributes to improve type safety and nullability awareness.

Access Modifiers & Redundant Code

  • Removed the internal access modifier from classes and records that did not require it, making them package-private and simplifying the file.

  • Removed redundant using directives and unnecessary comments, and suppressed certain ReSharper warnings for clarity.

@vbreuss vbreuss self-assigned this May 2, 2026
Copilot AI review requested due to automatic review settings May 2, 2026 06:16
@vbreuss vbreuss enabled auto-merge (squash) May 2, 2026 06:18
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 2, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the benchmark PR-comment formatter in the Nuke Pipeline project, primarily by adding nullable annotations and reshaping local declarations in BenchmarkReport.cs. This code sits in the build pipeline and is responsible for transforming BenchmarkDotNet markdown into the benchmark comment posted on pull requests.

Changes:

  • Added nullable-reference annotations to several BenchmarkReport and BenchmarkTableParser members.
  • Simplified many local declarations and access modifiers while preserving the benchmark table transformation logic.
  • Updated parser out parameters with nullable flow attributes to better describe success/failure behavior.

Comment thread Pipeline/BenchmarkReport.cs
Comment thread Pipeline/BenchmarkReport.cs Outdated
Comment thread Pipeline/BenchmarkReport.cs
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2026

Test Results

    24 files  ±0      24 suites  ±0   9m 57s ⏱️ -59s
 4 086 tests ±0   4 084 ✅ ±0  2 💤 ±0  0 ❌ ±0 
26 388 runs  ±0  26 384 ✅ ±0  4 💤 ±0  0 ❌ ±0 

Results for commit 66612ba. ± Comparison against base commit 6415600.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.72GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

CreateMock Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 66.16 ns 2.754 ns 2.576 ns 1.06 440 B 1.00
Mockolate 62.67 ns 1.451 ns 1.133 ns 1.00 440 B 1.00
Imposter 274.78 ns 4.468 ns 3.731 ns 4.39 2248 B 5.11
TUnitMocks 40.95 ns 0.748 ns 0.699 ns 0.65 224 B 0.51
Moq 1,367.73 ns 15.861 ns 13.245 ns 21.83 2096 B 4.76
NSubstitute 2,052.67 ns 36.786 ns 34.410 ns 32.76 5048 B 11.47
FakeItEasy 1,895.32 ns 45.396 ns 42.463 ns 30.25 2763 B 6.28
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 3.24GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Event Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 329.3 ns 5.45 ns 4.83 ns 1.13 1.78 KB 1.00
Mockolate 290.2 ns 1.20 ns 1.00 ns 1.00 1.78 KB 1.00
Imposter 1,293.3 ns 3.88 ns 3.44 ns 4.46 8.8 KB 4.94
TUnitMocks 173.9 ns 0.60 ns 0.47 ns 0.60 1.37 KB 0.77
Moq 16,043.5 ns 99.33 ns 88.06 ns 55.29 12.51 KB 7.02
NSubstitute 5,583.6 ns 22.67 ns 20.09 ns 19.24 9.05 KB 5.08
FakeItEasy 212,560.8 ns 278.14 ns 232.26 ns 732.52 15.26 KB 8.57
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.81GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Indexer N Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 1 904.5 ns 15.24 ns 13.51 ns 0.92 3.81 KB 1.00
Mockolate 1 983.9 ns 16.55 ns 15.48 ns 1.00 3.81 KB 1.00
Imposter 1 982.6 ns 28.43 ns 26.59 ns 1.00 5.16 KB 1.35
Moq 1 219,271.0 ns 577.92 ns 482.59 ns 222.90 20.37 KB 5.34
NSubstitute 1 9,753.5 ns 172.14 ns 161.02 ns 9.92 12.78 KB 3.35
FakeItEasy 1 12,094.2 ns 39.20 ns 36.67 ns 12.29 13.63 KB 3.57
baseline* 10 2,381.7 ns 33.53 ns 31.37 ns 0.95 4.87 KB 1.00
Mockolate 10 2,515.9 ns 19.04 ns 16.88 ns 1.00 4.87 KB 1.00
Imposter 10 2,282.5 ns 18.25 ns 17.07 ns 0.91 7.97 KB 1.64
Moq 10 231,523.8 ns 1,740.45 ns 1,628.02 ns 92.03 29.89 KB 6.14
NSubstitute 10 23,590.0 ns 78.45 ns 69.54 ns 9.38 25.58 KB 5.26
FakeItEasy 10 26,005.3 ns 222.17 ns 207.82 ns 10.34 32.97 KB 6.77
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.78GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method N Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 1 412.3 ns 5.27 ns 4.93 ns 1.14 2.04 KB 1.00
Mockolate 1 362.3 ns 10.70 ns 10.01 ns 1.00 2.04 KB 1.00
Imposter 1 543.2 ns 3.77 ns 3.34 ns 1.50 4.04 KB 1.98
TUnitMocks 1 638.9 ns 4.83 ns 4.28 ns 1.76 2.9 KB 1.42
Moq 1 182,318.3 ns 1,508.80 ns 1,259.92 ns 503.57 14.58 KB 7.15
NSubstitute 1 5,736.5 ns 112.92 ns 105.62 ns 15.84 9.12 KB 4.47
FakeItEasy 1 5,909.3 ns 22.44 ns 20.99 ns 16.32 8.05 KB 3.95
baseline* 10 725.7 ns 8.04 ns 6.71 ns 1.13 2.25 KB 1.00
Mockolate 10 643.6 ns 3.57 ns 2.98 ns 1.00 2.25 KB 1.00
Imposter 10 1,123.2 ns 30.55 ns 28.58 ns 1.75 5.52 KB 2.45
TUnitMocks 10 1,652.1 ns 11.36 ns 9.48 ns 2.57 4.49 KB 2.00
Moq 10 187,648.6 ns 384.16 ns 320.79 ns 291.59 18.48 KB 8.21
NSubstitute 10 8,197.7 ns 27.85 ns 21.74 ns 12.74 12.07 KB 5.37
FakeItEasy 10 9,049.8 ns 19.15 ns 15.99 ns 14.06 15.42 KB 6.85
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v4

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Property N Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 1 538.2 ns 10.76 ns 10.07 ns 0.86 2.46 KB 1.00
Mockolate 1 622.9 ns 5.68 ns 5.31 ns 1.00 2.46 KB 1.00
Imposter 1 554.5 ns 8.85 ns 7.84 ns 0.89 3.13 KB 1.27
TUnitMocks 1 837.5 ns 6.51 ns 6.09 ns 1.34 2.51 KB 1.02
Moq 1 11,551.2 ns 46.16 ns 40.92 ns 18.54 10.39 KB 4.22
NSubstitute 1 7,956.6 ns 16.16 ns 14.33 ns 12.77 11.45 KB 4.65
FakeItEasy 1 8,467.6 ns 24.07 ns 22.52 ns 13.59 11.25 KB 4.57
baseline* 10 1,109.8 ns 30.44 ns 28.47 ns 0.84 2.95 KB 1.00
Mockolate 10 1,320.1 ns 6.70 ns 6.26 ns 1.00 2.95 KB 1.00
Imposter 10 1,405.7 ns 17.97 ns 16.81 ns 1.06 4.67 KB 1.58
TUnitMocks 10 2,721.2 ns 10.78 ns 10.08 ns 2.06 4.66 KB 1.58
Moq 10 18,374.9 ns 45.72 ns 42.77 ns 13.92 18.28 KB 6.19
NSubstitute 10 17,163.2 ns 28.48 ns 25.25 ns 13.00 21.08 KB 7.14
FakeItEasy 10 19,167.3 ns 109.10 ns 102.05 ns 14.52 30.8 KB 10.43
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Callback Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 308.9 ns 1.22 ns 0.95 ns 0.90 1.68 KB 1.00
Mockolate 344.4 ns 10.88 ns 10.18 ns 1.00 1.68 KB 1.00
Imposter 428.9 ns 6.65 ns 5.89 ns 1.25 2.38 KB 1.42
TUnitMocks 626.8 ns 20.23 ns 18.93 ns 1.82 2.63 KB 1.56
Moq 99,186.6 ns 559.22 ns 523.09 ns 288.21 8.88 KB 5.29
NSubstitute 4,669.5 ns 36.10 ns 33.76 ns 13.57 7.74 KB 4.61
FakeItEasy 5,076.6 ns 19.08 ns 15.94 ns 14.75 6.81 KB 4.05

baseline* rows show the corresponding Mockolate benchmark from the most recent successful main branch build with results, for regression comparison.

Copilot AI review requested due to automatic review settings May 2, 2026 06:28
@vbreuss vbreuss force-pushed the topic/enable-nullable-for-benchmarkreport branch from 349d820 to a7a0fd3 Compare May 2, 2026 06:28
@vbreuss vbreuss force-pushed the topic/enable-nullable-for-benchmarkreport branch from a7a0fd3 to 49eb9ba Compare May 2, 2026 06:29
@vbreuss vbreuss disabled auto-merge May 2, 2026 06:29
@vbreuss vbreuss merged commit ba32c86 into main May 2, 2026
7 of 13 checks passed
@vbreuss vbreuss deleted the topic/enable-nullable-for-benchmarkreport branch May 2, 2026 06:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

Comment thread Pipeline/BenchmarkReport.cs
Comment thread Pipeline/BenchmarkReport.cs
Comment thread Pipeline/Build.csproj
Comment thread Pipeline/Build.csproj
Comment thread Pipeline/BenchmarkReport.cs
Comment thread Pipeline/BenchmarkReport.cs
Comment thread Pipeline/BenchmarkReport.cs
vbreuss added a commit that referenced this pull request May 2, 2026
This pull request refactors the `Pipeline/BenchmarkReport.cs` file to modernize and simplify the code, making it more idiomatic and concise. The changes focus on improving code readability, reducing redundancy, and leveraging newer C# features such as target-typed `new`, nullable reference types, and pattern-based null checks.

**Key improvements include:**

### Code Modernization & Simplification

* Replaced explicit type declarations with `var` where appropriate, streamlined null checks, and used target-typed `new` for object initialization, resulting in more concise and readable code throughout the file.

* Replaced multi-line `if` statements with single-line expressions where possible, and simplified method bodies by removing unnecessary braces and lines.

### Nullable Reference Types & Type Safety

* Updated methods and parameters to use nullable reference types (e.g., `string[]?`) and added `[NotNullWhen(true)]` attributes to improve type safety and nullability awareness.

### Access Modifiers & Redundant Code

* Removed the `internal` access modifier from classes and records that did not require it, making them package-private and simplifying the file.

* Removed redundant using directives and unnecessary comments, and suppressed certain ReSharper warnings for clarity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants