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
Make ValidatorProvider a Singleton #2864
Conversation
The Validator instance creation is quite expensive. Making this a Singleton reduced the CPU load by 50% and reduced the GC load from 5 GCs per second to 2 GCs per second when running a load test of the collector registration endpoint.
@@ -24,6 +24,6 @@ | |||
public class ValidatorModule extends AbstractModule { | |||
@Override | |||
protected void configure() { | |||
bind(Validator.class).toProvider(ValidatorProvider.class); | |||
bind(Validator.class).toProvider(ValidatorProvider.class).asEagerSingleton(); |
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.
It would be simpler to directly bind to the instance Validation.buildDefaultValidatorFactory().getValidator()
instead of using a singleton provider which basically returns a static field. This way we could get rid of the Provider<Validator>
.
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.
Good point, will change that.
Updated after review 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.
LGTM. 👍
The Validator instance creation is quite expensive. Making this a Singleton reduced the CPU load by 50% and reduced the GC load from 5 GCs per second to 2 GCs per second when running a load test of the collector registration endpoint.
Before
After