Purview.ZodSharp is designed for maximum performance: validation rules are readonly record structs, hot paths use Span<T>, and the source generator emits direct typed codegen with no reflection. The committed BenchmarkDotNet suite measures every scenario.
Results are written to BenchmarkDotNet.Artifacts/ (HTML, Markdown, logs) in the project directory. Use -c Release; the suite uses [MemoryDiagnoser] and a [SimpleJob] profile.
UUID validation uses a zero-allocation char-scan (version nibble at position 14, variant nibble at position 19) instead of a regex. Measured against the previous compiled regex:
Scenario
Mean
Allocated
Rule_CharScan_Valid (.UUID())
21.99 ns
0 B
Rule_LegacyRegex_Valid (previous implementation)
27.50 ns
0 B
Rule_CharScan_Invalid
< 1 ns
0 B
Rule_LegacyRegex_Invalid
14.22 ns
0 B
Rule_CharScan_Nil
20.67 ns
0 B
Rule_CharScanV7_Valid (.UUID(UuidVersion.V7))
20.89 ns
0 B
Rule_CharScanV7_Mismatch
20.11 ns
0 B
Schema_UUID_Valid
29.80 ns
0 B
Schema_UUIDV7_Valid
26.64 ns
0 B
The char-scan is ~20% faster than the previous regex on the valid path, is version-aware at no extra cost, and rejects wrong-length strings in under a nanosecond.
Source generation — [ZodSchema] emits direct property access and typed equality checks with no reflection (see Source Generator).
Fluent composition — schemas are immutable and shareable, so SchemaCache avoids repeated construction (see Compiled Validators and Caching).
The only allocations on a successful validation are the string transforms (ToLower/ToUpper/Trim produce new strings) and the union non-first-option paths noted above.