We have a PUT REST endpoint, which accepts an autogenerated object, which is in fact a list of objects. We send a request there, which contains around 23k of elements. Elements in that list have a couple of concrete implementations, each has a couple of required fields and a list with a couple more elements of the same type. When hibernate validator is enabled on that endpoint - it takes somewhere between 30 and 50 seconds to validate everything. When I replace that validation with manually written methods - it takes around 0.5 seconds to validate the same. The sample project to reproduce this is here: https://github.com/anatoliy-balakirev/hibernate_validator_performance_issue If you are on Linux, just run the following command in the root of the project (make sure your JAVA_HOME points to Java 17):
Or this on Windows:
And you’ll see these logs:
Which are basically about running three tests:
- endpoint_with_explicit_validation - validation is done with manually written method
- endpoint_with_validation - validation is done using Hibernate Validator
- endpoint_without_validation - no validation at all
If you want to see what exactly is being validated - uncomment this line: https://github.com/anatoliy-balakirev/hibernate_validator_performance_issue/blob/main/src/main/resources/application.properties#L1 I’m using the latest Spring Boot version (3.0.1), Java 17.0.5 (Amazon Corretto) and Maven 3.8.6 P.S. I’m not sure if this should be a Bug or rather an Improvement, so left the default one there. |