Skip to content

perf: Loop instead of Where().Any() in Matches#576

Merged
vbreuss merged 3 commits into
mainfrom
topic/Loop-instead-of-Where().Any()-in-Matches
Mar 25, 2026
Merged

perf: Loop instead of Where().Any() in Matches#576
vbreuss merged 3 commits into
mainfrom
topic/Loop-instead-of-Where().Any()-in-Matches

Conversation

@vbreuss

@vbreuss vbreuss commented Mar 25, 2026

Copy link
Copy Markdown
Member

Optimizes method invocation matching in Mockolate’s setup pipeline by replacing a LINQ-based mismatch check with an explicit loop, reducing allocations and iterator overhead during matching.

Key Changes:

  • Replace Where(...).Any() mismatch detection with early-return for loop.
  • Keep behavior equivalent while improving hot-path performance for parameter matching.

@vbreuss vbreuss self-assigned this Mar 25, 2026
Copilot AI review requested due to automatic review settings March 25, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Optimizes method invocation matching in Mockolate’s setup pipeline by replacing a LINQ-based mismatch check with an explicit loop, reducing allocations and iterator overhead during matching.

Changes:

  • Replace Where(...).Any() mismatch detection with early-return for loop.
  • Keep behavior equivalent while improving hot-path performance for parameter matching.

@github-actions

github-actions Bot commented Mar 25, 2026

Copy link
Copy Markdown

Test Results

    21 files  ±0      21 suites  ±0   4m 34s ⏱️ -27s
 2 792 tests ±0   2 791 ✅ ±0  1 💤 ±0  0 ❌ ±0 
18 763 runs  ±0  18 762 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 96090e4. ± Comparison against base commit 9dec11f.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Mar 25, 2026

Copy link
Copy Markdown

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 9V74 2.87GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.201
[Host] : .NET 10.0.5 (10.0.5, 10.0.526.15411), X64 RyuJIT x86-64-v3

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

Method Mean Error StdDev Gen0 Gen1 Allocated
Event_Mockolate 777.5 ns 6.82 ns 6.05 ns 0.1783 0.0010 2.91 KB
Event_Moq 11,242.7 ns 52.08 ns 43.49 ns 0.5493 - 9.69 KB
Event_NSubstitute 4,799.9 ns 49.16 ns 43.58 ns 0.5112 0.0076 8.4 KB
Event_FakeItEasy 211,068.0 ns 983.21 ns 919.70 ns 0.4883 0.2441 10.3 KB
Event_Imposter 971.0 ns 14.59 ns 13.65 ns 0.5093 0.0134 8.34 KB
Event_TUnitMocks 2,518.0 ns 166.99 ns 156.20 ns 0.2785 0.0057 4.55 KB
Indexer_Mockolate 1,267.2 ns 16.75 ns 15.66 ns 0.2747 0.0019 4.5 KB
Indexer_Moq 142,579.7 ns 755.28 ns 706.48 ns 0.7324 0.4883 14.56 KB
Indexer_NSubstitute 5,585.8 ns 58.88 ns 52.20 ns 0.5722 - 9.41 KB
Indexer_FakeItEasy 5,633.9 ns 103.44 ns 96.76 ns 0.4883 0.0153 7.98 KB
Indexer_Imposter 762.2 ns 16.06 ns 15.02 ns 0.2928 0.0048 4.8 KB
Method_Mockolate 986.7 ns 13.67 ns 12.79 ns 0.2117 - 3.47 KB
Method_Moq 143,477.9 ns 693.67 ns 648.86 ns 0.7324 0.4883 14.58 KB
Method_NSubstitute 5,435.4 ns 135.22 ns 126.49 ns 0.5493 0.0076 9.09 KB
Method_FakeItEasy 5,612.5 ns 135.14 ns 126.41 ns 0.4883 0.0153 8 KB
Method_Imposter 593.2 ns 4.75 ns 4.45 ns 0.2537 0.0029 4.15 KB
Method_TUnitMocks 2,797.1 ns 62.23 ns 58.21 ns 0.4005 0.0076 6.55 KB
Property_Mockolate 1,121.8 ns 23.23 ns 21.73 ns 0.2117 - 3.46 KB
Property_Moq 4,226.1 ns 27.35 ns 25.59 ns 0.3281 - 5.47 KB
Property_NSubstitute 4,667.5 ns 79.19 ns 74.07 ns 0.5188 0.0076 8.58 KB
Property_FakeItEasy 4,016.4 ns 71.87 ns 67.23 ns 0.3815 0.0153 6.29 KB
Property_Imposter 386.1 ns 4.52 ns 4.01 ns 0.1783 0.0019 2.91 KB
Property_TUnitMocks 2,218.1 ns 82.02 ns 76.72 ns 0.3319 0.0076 5.47 KB

@vbreuss vbreuss force-pushed the topic/Loop-instead-of-Where().Any()-in-Matches branch from 8f85172 to 96090e4 Compare March 25, 2026 16:15
Copilot AI review requested due to automatic review settings March 25, 2026 16:15

Copilot AI left a comment

Copy link
Copy Markdown

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 6 out of 6 changed files in this pull request and generated no new comments.

@sonarqubecloud

Copy link
Copy Markdown

@vbreuss vbreuss merged commit 60793ce into main Mar 25, 2026
16 checks passed
@vbreuss vbreuss deleted the topic/Loop-instead-of-Where().Any()-in-Matches branch March 25, 2026 16:25
@github-actions

Copy link
Copy Markdown

This is addressed in release v2.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants