go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
17k stars 1.33k forks source link

Lazily initialize regexes to speed up `init()` #1277

Closed kylecarbs closed 5 months ago

kylecarbs commented 5 months ago

Using GODEBUG=inittrace=1 I found a relatively constant 10ms init caused by this function.

Replaces #1246.

@go-playground/validator-maintainers

kylecarbs commented 5 months ago

@deankarn sorry for the PR spam, other one automatically closed! 🤦

I changed this to use sync.Once, which I agree is cleaner.

coveralls commented 5 months ago

Coverage Status

coverage: 74.272% (+0.02%) from 74.257% when pulling 9ded6c51ac8e1ac338e0342f12f8d44df0185bbc on kylecarbs:master into c7e85182ab05a4b302bca82a86f1f09530bd2bc1 on go-playground:master.