Skip to content

Commit 89af895

Browse files
committed
Fix reference bug introduced by performance optimization by using class instead of struct.
1 parent 0736e6d commit 89af895

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

CodingFlow.FluentValidation/FluentValidation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/// The returned chained object for the fluent API.
55
/// </summary>
66
/// <typeparam name="T">Input type.</typeparam>
7-
public record struct FluentValidation<T>
7+
public class FluentValidation<T>
88
{
99
internal ValidationResult Result { get; init; }
1010

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To change this file edit the source file and then run MarkdownSnippets.
1414

1515
Minimal, easy to use fluent validations API inspired by [FluentValidation](https://github.com/FluentValidation/FluentValidation).
1616

17-
When you need to validate any type, even primitives in an easy and direct way, this library fits the bill. FluentValidation by Jeremy Skinner requires creating a separate validator class to register validation rules, and then instantiating the validator class. This library on the other hand, let's you add validation directly. This library is also ~ 25% faster performance-wise (See [performance benchmark](#performance-benchmark-comparison-with-fluentvalidation)).
17+
When you need to validate any type, even primitives in an easy and direct way, this library fits the bill. FluentValidation by Jeremy Skinner requires creating a separate validator class to register validation rules, and then instantiating the validator class. This library on the other hand, let's you add validation directly. This library is also ~ 20% faster performance-wise (See [performance benchmark](#performance-benchmark-comparison-with-fluentvalidation)).
1818

1919
# Usage
2020

@@ -221,8 +221,8 @@ public readonly partial struct Age
221221

222222
# Performance Benchmark Comparison with FluentValidation
223223

224-
Benchmark of inclusive between validator shows this library is ~ 25% faster
225-
than FluentValidation.
224+
Benchmark of inclusive between validator shows this library is ~ 20 - 25% faster
225+
than FluentValidation in .NET 9 and .NET 10.
226226

227227
```
228228
BenchmarkDotNet v0.15.8, Windows 11 (10.0.26200.7462/25H2/2025Update/HudsonValley2)
@@ -233,15 +233,15 @@ Intel Core Ultra 5 245KF 4.20GHz, 1 CPU, 14 logical and 14 physical cores
233233
.NET 8.0 : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
234234
.NET 9.0 : .NET 9.0.11 (9.0.11, 9.0.1125.51716), X64 RyuJIT x86-64-v3
235235
```
236-
237236
| Method | Job | Runtime | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
238237
|----------------- |---------- |---------- |---------:|---------:|---------:|-------:|-------:|----------:|
239-
| CodingFlow | .NET 10.0 | .NET 10.0 | 34.58 ns | 0.154 ns | 0.144 ns | 0.0249 | - | 312 B |
240-
| FluentValidation | .NET 10.0 | .NET 10.0 | 46.73 ns | 0.527 ns | 0.493 ns | 0.0471 | 0.0001 | 592 B |
241-
| CodingFlow | .NET 8.0 | .NET 8.0 | 42.22 ns | 0.418 ns | 0.391 ns | 0.0249 | - | 312 B |
242-
| FluentValidation | .NET 8.0 | .NET 8.0 | 52.87 ns | 0.390 ns | 0.365 ns | 0.0471 | 0.0001 | 592 B |
243-
| CodingFlow | .NET 9.0 | .NET 9.0 | 35.42 ns | 0.211 ns | 0.187 ns | 0.0249 | - | 312 B |
244-
| FluentValidation | .NET 9.0 | .NET 9.0 | 48.73 ns | 0.175 ns | 0.164 ns | 0.0471 | 0.0001 | 592 B |
238+
| CodingFlow | .NET 10.0 | .NET 10.0 | 34.70 ns | 0.338 ns | 0.316 ns | 0.0235 | - | 296 B |
239+
| FluentValidation | .NET 10.0 | .NET 10.0 | 46.42 ns | 0.228 ns | 0.213 ns | 0.0471 | 0.0001 | 592 B |
240+
| CodingFlow | .NET 8.0 | .NET 8.0 | 47.44 ns | 0.538 ns | 0.503 ns | 0.0287 | - | 360 B |
241+
| FluentValidation | .NET 8.0 | .NET 8.0 | 52.02 ns | 0.387 ns | 0.323 ns | 0.0471 | 0.0001 | 592 B |
242+
| CodingFlow | .NET 9.0 | .NET 9.0 | 37.48 ns | 0.149 ns | 0.139 ns | 0.0287 | - | 360 B |
243+
| FluentValidation | .NET 9.0 | .NET 9.0 | 48.27 ns | 0.499 ns | 0.467 ns | 0.0471 | 0.0001 | 592 B |
244+
245245

246246
Benchmark code:
247247

README.source.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Minimal, easy to use fluent validations API inspired by [FluentValidation](https://github.com/FluentValidation/FluentValidation).
99

10-
When you need to validate any type, even primitives in an easy and direct way, this library fits the bill. FluentValidation by Jeremy Skinner requires creating a separate validator class to register validation rules, and then instantiating the validator class. This library on the other hand, let's you add validation directly. This library is also ~ 25% faster performance-wise (See [performance benchmark](#performance-benchmark-comparison-with-fluentvalidation)).
10+
When you need to validate any type, even primitives in an easy and direct way, this library fits the bill. FluentValidation by Jeremy Skinner requires creating a separate validator class to register validation rules, and then instantiating the validator class. This library on the other hand, let's you add validation directly. This library is also ~ 20% faster performance-wise (See [performance benchmark](#performance-benchmark-comparison-with-fluentvalidation)).
1111

1212
# Usage
1313

@@ -99,8 +99,8 @@ snippet: VogenExample
9999

100100
# Performance Benchmark Comparison with FluentValidation
101101

102-
Benchmark of inclusive between validator shows this library is ~ 25% faster
103-
than FluentValidation.
102+
Benchmark of inclusive between validator shows this library is ~ 20 - 25% faster
103+
than FluentValidation in .NET 9 and .NET 10.
104104

105105
```
106106
BenchmarkDotNet v0.15.8, Windows 11 (10.0.26200.7462/25H2/2025Update/HudsonValley2)
@@ -111,15 +111,15 @@ Intel Core Ultra 5 245KF 4.20GHz, 1 CPU, 14 logical and 14 physical cores
111111
.NET 8.0 : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
112112
.NET 9.0 : .NET 9.0.11 (9.0.11, 9.0.1125.51716), X64 RyuJIT x86-64-v3
113113
```
114-
115114
| Method | Job | Runtime | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
116115
|----------------- |---------- |---------- |---------:|---------:|---------:|-------:|-------:|----------:|
117-
| CodingFlow | .NET 10.0 | .NET 10.0 | 34.58 ns | 0.154 ns | 0.144 ns | 0.0249 | - | 312 B |
118-
| FluentValidation | .NET 10.0 | .NET 10.0 | 46.73 ns | 0.527 ns | 0.493 ns | 0.0471 | 0.0001 | 592 B |
119-
| CodingFlow | .NET 8.0 | .NET 8.0 | 42.22 ns | 0.418 ns | 0.391 ns | 0.0249 | - | 312 B |
120-
| FluentValidation | .NET 8.0 | .NET 8.0 | 52.87 ns | 0.390 ns | 0.365 ns | 0.0471 | 0.0001 | 592 B |
121-
| CodingFlow | .NET 9.0 | .NET 9.0 | 35.42 ns | 0.211 ns | 0.187 ns | 0.0249 | - | 312 B |
122-
| FluentValidation | .NET 9.0 | .NET 9.0 | 48.73 ns | 0.175 ns | 0.164 ns | 0.0471 | 0.0001 | 592 B |
116+
| CodingFlow | .NET 10.0 | .NET 10.0 | 34.70 ns | 0.338 ns | 0.316 ns | 0.0235 | - | 296 B |
117+
| FluentValidation | .NET 10.0 | .NET 10.0 | 46.42 ns | 0.228 ns | 0.213 ns | 0.0471 | 0.0001 | 592 B |
118+
| CodingFlow | .NET 8.0 | .NET 8.0 | 47.44 ns | 0.538 ns | 0.503 ns | 0.0287 | - | 360 B |
119+
| FluentValidation | .NET 8.0 | .NET 8.0 | 52.02 ns | 0.387 ns | 0.323 ns | 0.0471 | 0.0001 | 592 B |
120+
| CodingFlow | .NET 9.0 | .NET 9.0 | 37.48 ns | 0.149 ns | 0.139 ns | 0.0287 | - | 360 B |
121+
| FluentValidation | .NET 9.0 | .NET 9.0 | 48.27 ns | 0.499 ns | 0.467 ns | 0.0471 | 0.0001 | 592 B |
122+
123123

124124
Benchmark code:
125125

0 commit comments

Comments
 (0)