-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Optimize startup time: make validation initialization lazy #7579
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
Comments
Will target to 1.5 to see what are options are. It might slip. |
I think this should be DevTools-specific or opt-in. In production, I'd prefer to pay the cost of validation initialisation at startup and be safe in the knowledge that it's initialised successfully rather than deferring the cost and potential failure until a request is routed to the app. |
It's also used in |
We can't do that. Validation is an advertized feature so users are free to use it as advertized (read in their config properties). I don't think that changing something for our own code is something we should ever do if the related feature is public. |
I did a bit of digging with this, it seems like the majority of the time is spent trying to work out of a 95% of our properties classes don't use JSR-330 constraints, I think if we switch validation off for our classes, but leave it on for user defined configuration classes, we should be able to improve startup time. |
I think it would be easier to require |
Experimental branch https://github.com/philwebb/spring-boot/tree/gh-7579 |
@snicoll I like that idea, but is it a sensible change for 1.5? My approach so far has been to add a |
Change isn't noticeable in before
after
But it is for Pet Clinic: before
after
|
That flag is better if you want this to be made 100% transparent but it's a bit weird. Someone might wonder why you wouldn't want validation in the first place. Our reasoning here is performance so making it that opt-in (i.e. you need the relevant annotation now) makes more sense to me. Surely the current state is awesome because nobody has to change anything but I fear we'll regret that design pretty soon. |
I like the idea of requiring I think we either need to jump straight into |
+1 for |
Seems like |
Update use of `@ConfigurationProperties` to prefer the more explicit `prefix` attribute, rather than `value`. See gh-7579
Replace JSR-330 validation annotations from all internal `@ConfigurationProperties` classes with standard Asserts. Prior to this commit validation of our own configuration properties would only occur when the user happens to have compliant JSR-330 implementation on their classpath. See gh-7579
For 1.5 we'll still validate all configuration classes (with the exception of Spring Boot's own) even if there's not a |
Hi @philwebb , I tried this feature using latest snapshot version of 1.5.
Is this behavior work as design ? |
@kazuki43zoo Once only would be better |
@philwebb quick question regarding the use of Is this how it should be done on all properties classes from now on? |
@bclozel I think setters might actually be better. I tried them at one point but hit some issues (I can't remember why). I'd say try setters first. |
I'll try to fix the ones I changed. |
@philwebb the only use case I have in mind is if you set the value to |
We're going to live with the double log message. I've replaced the |
If I'm not really using validation except in the web tier it's wasteful to initialize it on startup, and it's expensive: 200-300ms out of 3s to start a Pet Clinic.
The text was updated successfully, but these errors were encountered: