Skip to content

perf: filter recorded events without a closure per event - #1801

Merged
vbreuss merged 1 commit into
mainfrom
perf/event-filter-without-closure
Oct 11, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/event-filter-without-closure

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

With a filter such as WithSender, every recorded event was checked through List.TrueForAll with a lambda that captured the event parameters, which allocated a closure and a delegate per event and evaluation.

Benchmark (10 recorded events) Before After
Triggered(...).WithSender(p => p == player).AtLeast(10.Times()) 926.8 ns / 3.95 KB 825.8 ns / 3.09 KB

With a filter such as `WithSender`, every recorded event was checked through `List.TrueForAll` with a lambda that captured the event parameters, which allocated a closure and a delegate per event and evaluation.

| Benchmark (10 recorded events) | Before | After |
|---|---:|---:|
| `Triggered(...).WithSender(p => p == player).AtLeast(10.Times())` | 926.8 ns / 3.95 KB | 825.8 ns / 3.09 KB |
@vbreuss vbreuss self-assigned this Oct 11, 2026
@vbreuss
vbreuss enabled auto-merge (squash) October 11, 2026 10:23
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 New issue

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     91 files       91 suites   1h 46m 56s ⏱️
 37 522 tests  37 522 ✅ 0 💤 0 ❌
217 902 runs  217 902 ✅ 0 💤 0 ❌

Results for commit 6a6a1fd.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
Intel Xeon 6973P-C 2.60GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.303
[Host] : .NET 8.0.31 (8.0.31, 8.0.3126.42015), X64 RyuJIT x86-64-v4

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

Method Mean vs aweXpect Error StdDev Gen0 Gen1 Allocated vs aweXpect
Contains_aweXpect 388.8 ns 1.81 ns 1.41 ns 0.0086 - 728 B
Contains_FluentAssertions 382.8 ns -2% 2.87 ns 2.24 ns 0.0191 - 1608 B +121%
Contains_TUnit 340.6 ns -12% 0.97 ns 0.86 ns 0.0100 - 848 B +16%
Equivalency_aweXpect 7,593.2 ns 96.45 ns 85.50 ns 0.0458 - 4032 B
Equivalency_FluentAssertions 234,230.5 ns +2985% 2,967.29 ns 2,630.42 ns 6.8359 - 590225 B +14539%
Equivalency_TUnit 13,421.8 ns +77% 445.75 ns 416.96 ns 0.1831 - 15680 B +289%
EventTriggered_aweXpect 593.6 ns 17.32 ns 15.35 ns 0.0219 - 1840 B
EventTriggered_FluentAssertions 35,096.6 ns +5813% 1,020.66 ns 954.72 ns 0.0610 0.0305 5256 B +186%
Int_GreaterThan_aweXpect 134.9 ns 1.69 ns 1.50 ns 0.0064 - 544 B
Int_GreaterThan_FluentAssertions 276.1 ns +105% 4.60 ns 4.31 ns 0.0143 - 1224 B +125%
Int_GreaterThan_TUnit 187.0 ns +39% 2.04 ns 1.81 ns 0.0091 - 776 B +43%
ItemsCount_AtLeast_aweXpect 14,457.0 ns 127.50 ns 119.26 ns 0.1068 - 9592 B
ItemsCount_AtLeast_FluentAssertions 1,245.7 ns -91% 9.63 ns 8.04 ns 0.0229 - 2008 B -79%
ItemsCount_AtLeast_TUnit 1,069.5 ns -93% 22.99 ns 21.51 ns 0.0114 - 1064 B -89%
Multiple_aweXpect 726.4 ns 14.24 ns 11.12 ns 0.0257 - 2168 B
Multiple_FluentAssertions 1,615.7 ns +122% 38.58 ns 36.09 ns 0.0801 - 6744 B +211%
Multiple_TUnit 694.0 ns -4% 4.99 ns 4.17 ns 0.0267 - 2240 B +3%
Satisfies_aweXpect 149.8 ns 3.18 ns 2.97 ns 0.0069 - 584 B
Satisfies_FluentAssertions 14,207.8 ns +9383% 325.40 ns 304.38 ns 0.0610 0.0458 5614 B +861%
Satisfies_TUnit 185.2 ns +24% 3.53 ns 3.30 ns 0.0083 - 712 B +22%
String_aweXpect 207.2 ns 3.24 ns 2.71 ns 0.0072 - 608 B
String_FluentAssertions 525.1 ns +153% 13.38 ns 12.52 ns 0.0267 - 2304 B +279%
String_TUnit 276.9 ns +34% 2.27 ns 2.12 ns 0.0105 - 912 B +50%
StringArray_aweXpect 437.1 ns 10.05 ns 8.91 ns 0.0105 - 896 B
StringArray_FluentAssertions 1,170.1 ns +168% 12.34 ns 11.54 ns 0.0496 - 4152 B +363%
StringArray_TUnit 528.1 ns +21% 6.23 ns 5.52 ns 0.0143 - 1264 B +41%
StringArrayInAnyOrder_aweXpect 666.4 ns 8.05 ns 7.53 ns 0.0153 - 1304 B
StringArrayInAnyOrder_FluentAssertions 14,004.7 ns +2002% 224.91 ns 187.81 ns 0.3967 - 33465 B +2466%
StringArrayInAnyOrder_TUnit 636.2 ns -5% 2.80 ns 2.62 ns 0.0162 - 1408 B +8%
Throws_aweXpect 8,181.6 ns 15.43 ns 13.68 ns 0.0153 - 2360 B
Throws_FluentAssertions 24,901.4 ns +204% 552.78 ns 517.07 ns 0.2136 - 18608 B +688%
Throws_TUnit 7,132.0 ns -13% 120.89 ns 113.08 ns 0.0153 - 1824 B -23%
ThrowsAsync_aweXpect 14,571.5 ns 149.92 ns 132.90 ns 0.0305 - 3064 B
ThrowsAsync_FluentAssertions 35,270.0 ns +142% 307.69 ns 256.93 ns 0.2441 - 23553 B +669%
ThrowsAsync_TUnit 14,144.6 ns -3% 311.11 ns 291.01 ns 0.0305 - 2920 B -5%

@vbreuss
vbreuss merged commit 731c81e into main Oct 11, 2026
15 of 16 checks passed
@vbreuss
vbreuss deleted the perf/event-filter-without-closure branch October 11, 2026 11:20
vbreuss added a commit that referenced this pull request Oct 11, 2026
Sonar asks to replace the `foreach` loop of the event filter with `All`, which would bring back the closure per recorded event that #1801 removed. A `for` loop keeps the filter free of allocations without the finding.
@github-actions github-actions Bot added the state: released The issue is released label Oct 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This is addressed in release v3.1.0.

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.

1 participant