govalid

High-performance, type-safe validation library for Go with zero allocations

Benchmarks

Performance comparison between govalid and reflection-based validators

Performance Benchmarks

govalid is designed for maximum performance with zero allocations. Here are the latest benchmark results comparing govalid with reflection-based validators.

Latest Results

Benchmarked on: 2025-07-15
Platform: Darwin 24.5.0 arm64
Go version: go1.25-devel_a8e99ab19c

Raw Benchmark Data

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
BenchmarkGoValidCELConcurrent-16             	1000000000	         0.09323 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidCELMultipleExpressions-16    	1000000000	         0.8409 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidCELCacheEffectiveness-16     	1000000000	         0.1015 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidCELBasic-16                  	618011162	         1.946 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidCELCrossField-16             	617148498	         1.953 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidCELStringLength-16           	605757344	         1.949 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidCELNumericComparison-16      	581620783	         2.036 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidEmail-16                     	31846465	        38.24 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundEmail-16                	 1840472	       649.4 ns/op	      90 B/op	       5 allocs/op
BenchmarkGoValidatorEmail-16                 	 1976113	       606.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkOzzoValidationEmail-16              	27997833	        44.04 ns/op	      24 B/op	       1 allocs/op
BenchmarkGookitValidateEmail-16              	  121108	     10481 ns/op	   16065 B/op	      74 allocs/op
BenchmarkGoValidEnum-16                      	539168131	         2.231 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidGT-16                        	609764490	         1.936 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundGT-16                   	19207836	        63.00 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidatorGT-16                    	21764314	        54.44 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidGTE-16                       	610084184	         1.946 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundGTE-16                  	19815618	        60.30 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidLT-16                        	626116629	         1.916 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundLT-16                   	19840449	        60.77 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidLTE-16                       	625070131	         1.969 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundLTE-16                  	19450260	        61.91 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidMaxItems-16                  	479873872	         2.520 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundMaxItems-16             	14759504	        80.30 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidMaxLength-16                 	77328928	        15.67 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundMaxLength-16            	16308603	        73.50 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidatorMaxLength-16             	 7367277	       161.6 ns/op	      32 B/op	       2 allocs/op
BenchmarkOzzoValidationMaxLength-16          	 6660802	       183.4 ns/op	     432 B/op	       4 allocs/op
BenchmarkGookitValidateMaxLength-16          	  115408	     10276 ns/op	   15632 B/op	      80 allocs/op
BenchmarkGoValidMinItems-16                  	428160852	         2.785 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundMinItems-16             	14833287	        79.81 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidMinLength-16                 	100000000	        11.60 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundMinLength-16            	17671692	        67.51 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidatorMinLength-16             	 7323378	       165.1 ns/op	      32 B/op	       2 allocs/op
BenchmarkGoValidRequired-16                  	623661589	         1.935 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundRequired-16             	13981681	        85.51 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidatorRequired-16              	625855254	         1.925 ns/op	       0 B/op	       0 allocs/op
BenchmarkOzzoValidationRequired-16           	33811228	        34.91 ns/op	      24 B/op	       1 allocs/op
BenchmarkGookitValidateRequired-16           	  117372	     10089 ns/op	   15472 B/op	      72 allocs/op
BenchmarkGoValidURL-16                       	27992418	        42.54 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundURL-16                  	 4223242	       287.9 ns/op	     144 B/op	       1 allocs/op
BenchmarkGoValidatorURL-16                   	  149181	      7887 ns/op	     144 B/op	       1 allocs/op
BenchmarkOzzoValidationURL-16                	  153288	      7825 ns/op	     171 B/op	       2 allocs/op
BenchmarkGookitValidateURL-16                	  113994	      9850 ns/op	   15641 B/op	      75 allocs/op
BenchmarkGoValidUUID-16                      	32124428	        37.69 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoPlaygroundUUID-16                 	 4753952	       254.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkGoValidatorUUID-16                  	 6066202	       197.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkOzzoValidationUUID-16               	 5034348	       238.0 ns/op	      24 B/op	       1 allocs/op
BenchmarkGookitValidateUUID-16               	  113701	     10603 ns/op	   15519 B/op	      74 allocs/op

Performance Comparison

vs go-playground/validator

Validatorgovalid (ns/op)go-playground/validator (ns/op)Improvementgovalid AllocsCompetitor Allocs
Email38.24ns649.417.0x faster0 allocs/op5 allocs + 90 B/op
GT1.936ns63.0032.5x faster0 allocs/op0 allocs/op
GTE1.946ns60.3031.0x faster0 allocs/op0 allocs/op
LT1.916ns60.7731.7x faster0 allocs/op0 allocs/op
LTE1.969ns61.9131.4x faster0 allocs/op0 allocs/op
MaxItems2.520ns80.3031.9x faster0 allocs/op0 allocs/op
MaxLength15.67ns73.504.7x faster0 allocs/op0 allocs/op
MinItems2.785ns79.8128.7x faster0 allocs/op0 allocs/op
MinLength11.60ns67.515.8x faster0 allocs/op0 allocs/op
Required1.935ns85.5144.2x faster0 allocs/op0 allocs/op
URL42.54ns287.96.8x faster0 allocs/op1 allocs + 144 B/op
UUID37.69ns254.06.7x faster0 allocs/op0 allocs/op
Enum2.242nsN/A (govalid exclusive)govalid exclusive0 allocs/opN/A

vs go-validator/validator

Validatorgovalid (ns/op)go-validator/validator (ns/op)Improvementgovalid AllocsCompetitor Allocs
Email36.80ns584.115.9x faster0 allocs/op0 allocs/op
GT1.825ns53.5729.4x faster0 allocs/op0 allocs/op
MaxLength15.58ns155.710.0x faster0 allocs/op2 allocs + 32 B/op
MinLength11.46ns159.613.9x faster0 allocs/op2 allocs + 32 B/op
Required1.914ns1.9291.0x faster0 allocs/op0 allocs/op
URL41.68ns7776186.5x faster0 allocs/op1 allocs + 146 B/op
UUID36.21ns193.15.3x faster0 allocs/op0 allocs/op

vs ozzo-validation

Validatorgovalid (ns/op)ozzo-validation (ns/op)Improvementgovalid AllocsCompetitor Allocs
Email36.80ns39.351.1x faster0 allocs/op1 allocs + 24 B/op
MaxLength15.58ns159.310.2x faster0 allocs/op4 allocs + 432 B/op
Required1.914ns33.6917.6x faster0 allocs/op1 allocs + 24 B/op
URL41.68ns7739185.6x faster0 allocs/op2 allocs + 170 B/op
UUID36.21ns231.56.4x faster0 allocs/op1 allocs + 24 B/op

vs gookit/validate

Validatorgovalid (ns/op)gookit/validate (ns/op)Improvementgovalid AllocsCompetitor Allocs
Email36.80ns9559259.8x faster0 allocs/op74 allocs + 15952 B/op
MaxLength15.58ns9125585.5x faster0 allocs/op80 allocs + 15632 B/op
Required1.914ns86984543.1x faster0 allocs/op72 allocs + 15472 B/op
URL41.68ns9216221.1x faster0 allocs/op75 allocs + 15641 B/op
UUID36.21ns9256255.6x faster0 allocs/op74 allocs + 15514 B/op

Key Performance Insights

1. Zero Allocations

All govalid validators perform zero heap allocations, while competitors often allocate 0-5 objects per validation.

2. Sub-Nanosecond Efficiency

Simple validators (GT, LT, Required) execute in under 2ns, making them essentially free operations.

3. Complex Validation Optimization

Even complex validators like email and URL are optimized with:

  • Manual string parsing (no regex overhead)
  • Single-pass validation algorithms
  • Zero memory allocations

4. String Length Performance

Unicode-aware string validators are 4.8-6.0x faster despite proper UTF-8 handling.

govalid-Exclusive Features

Enum Validation

1
2
// +govalid:enum=admin,user,guest
Role string
  • Performance: ~2.2ns with 0 allocations
  • No equivalent in go-playground/validator
  • Supports string, numeric, and custom types

Extended Collection Support

1
2
3
4
5
// +govalid:maxitems=10
Items map[string]int  // Maps supported!

// +govalid:minitems=1
Channel chan string   // Channels supported!

Optimization Techniques

1. Code Generation

  • Compile-time validation functions (no runtime reflection)
  • Inlined simple operations for maximum speed
  • Direct field access with no interface overhead

2. External Helper Functions

Complex validators use optimized external functions for better performance.

3. Manual String Parsing

  • Character-by-character parsing instead of strings.Split
  • Direct indexing instead of strings.Contains
  • Single-pass algorithms for complex validation

4. Memory Optimization

  • Zero heap allocations across all validators
  • Stack-only operations for maximum cache efficiency
  • Minimal memory footprint in generated code

Running Benchmarks

To run benchmarks yourself:

1
2
3
4
5
6
# Sync all benchmark documentation
make sync-benchmarks

# Run benchmarks manually
cd test
go test ./benchmark/ -bench=. -benchmem

Conclusion

govalid delivers exceptional performance improvements across all reflection-based validators:

Performance Improvements by Library

  • vs go-playground/validator: 4.8x to 44.8x faster
  • vs go-validator/validator: 1.0x to 186.5x faster
  • vs ozzo-validation: 1.1x to 185.6x faster
  • vs gookit/validate: 221.1x to 4543.1x faster

Additional Benefits

  • Zero allocations across all validators (vs 0-80 allocs for competitors)
  • Sub-3ns performance for simple operations
  • Extended type support (maps, channels, enums)
  • Production-ready with comprehensive test coverage

Choose govalid when performance matters and zero allocations are critical for your application’s success.