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() #1246

Closed
wants to merge 0 commits into from

Conversation

kylecarbs
Copy link
Contributor

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

@go-playground/validator-maintainers

@kylecarbs kylecarbs requested a review from a team as a code owner April 1, 2024 20:01
@coveralls
Copy link

coveralls commented Apr 1, 2024

Coverage Status

coverage: 74.228% (+0.02%) from 74.208%
when pulling cebbc77 on kylecarbs:master
into a0f74b0 on go-playground:master.

@kylecarbs kylecarbs changed the title Lazily initialize postcode regexes to speed up init() Lazily initialize regexes to speed up init() Apr 1, 2024
@deankarn
Copy link
Contributor

@kylecarbs out of curiosity, what is your use case where 10ms is not tolerable?

@kylecarbs
Copy link
Contributor Author

@deankarn this package is imported in our CLI. Adding that overhead to every invocation (even help) isn't great.

@kylecarbs
Copy link
Contributor Author

@deankarn any changes needed for me to push this through?

@deankarn
Copy link
Contributor

deankarn commented Jun 1, 2024

@kylecarbs sorry for the lateness of my reply, been busy.

My only concern is the sync.Mutex overhead for longer running applications, can you change the implementation to use sync.Once instead which uses lower level atomics?

@kylecarbs
Copy link
Contributor Author

@deankarn good idea. Will change in a bit!

@deankarn
Copy link
Contributor

deankarn commented Jun 1, 2024

I will check back later tonight/tomorrow :)

@kylecarbs kylecarbs closed this Jun 11, 2024
kylecarbs added a commit to kylecarbs/validator that referenced this pull request Jun 11, 2024
Using `GODEBUG=inittrace=1` I found a relatively constant 10ms init caused by this function.

Replaces go-playground#1246.
deankarn pushed a commit that referenced this pull request Jun 12, 2024
Using `GODEBUG=inittrace=1` I found a relatively constant 10ms init
caused by this function.

Replaces #1246.

@go-playground/validator-maintainers
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