-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Create ValidatorFactory just once #6800
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
Create ValidatorFactory just once #6800
Conversation
|
We could even backport this. |
|
Are you sure is it being injected for every constraints and for each request? I think that it is created every time a Validar is injected (contrary to every time it is needed). And it is injected only into Finally, maybe we could just bind and inject the |
|
@marcospereira You are completely right - it only gets injected once (for the Anyway I would still merge this pull request because it makes it clear there is only one form factory per app (even though in our case it is like this anyway because of the singleton). This is also what the hibernate validation documention says:
So I think my change still is valid. About injecting the Please also have a look at the second commit I added. We never cleaned up our validator factory when the app stopped:
|
marcospereira
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkurz looks good to me.
+1 for backport it to 2.5.x.
* Create validatorFactory just once * Close validatorFactory when app stops
|
2.5.x: d283729 |
|
We also should be checking for binary compatibility before merging (using |
|
@gmethvin and @mkurz, this could be a good point in favor to prefer to backport using a new PR instead of manually doing it to master (or version) branch. Travis would warning us (at the PR checks) that the build was failing because of binary compatibility problems: https://travis-ci.org/playframework/playframework/builds/184239230 So, maybe a good rule of thumb is that, if you are adding/changing/removing methods, do the backport/forwardport using a PR. WDYT? |
|
I agree. |
|
@marcospereira @gmethvin Sorry about that. I will create a PR next time. |
Right now we create a
ValidatorFactoryeach time we need a validator - which is quite often (for every constraint annotation for each request).But we just need a single
ValidatorFactoryper app which delivers us the desired validator(s).Also using
usingContextisn't ideal here. What we do right now we create aValidationFactoryviabuildDefaultValidatorFactory(which actually is just a shortcut for.byDefaultProvider().configure().buildValidatorFactory()) and then re-configure this just created factory viausingContext(). With my change we now immediately create the factory we want.This change will save some CPU cycles and heap space 😆