Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily initialize regexes to speed up init() #1277

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

kylecarbs
Copy link
Contributor

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

Replaces #1246.

@go-playground/validator-maintainers

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

Replaces go-playground#1246.
@kylecarbs kylecarbs requested a review from a team as a code owner June 11, 2024 12:33
@kylecarbs
Copy link
Contributor Author

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

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

@coveralls
Copy link

Coverage Status

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

@kylecarbs kylecarbs changed the title Lazily initialize regexes to speed up `init() Lazily initialize regexes to speed up init() Jun 11, 2024
@deankarn deankarn merged commit 2e1df48 into go-playground:master Jun 12, 2024
15 checks passed
nieomylnieja added a commit to nobl9/govy that referenced this pull request Sep 19, 2024
## Motivation

We should aim at limiting initial load time when importing the library,
one of the contributors to the initial load time are compilations of
regular expressions. We should avoid loading all of them at once, but
rather lazy load the ones which are used by users once.

## Related Changes

go-playground/validator#1277

## Release Notes

All regular expressions are now lazy loaded, once when the corresponding
rule is used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants