hibernate-validator icon indicating copy to clipboard operation
hibernate-validator copied to clipboard

HV-1831 Optimize cascading validation for large lists

Open marko-bekhta opened this issue 2 years ago • 3 comments

https://hibernate.atlassian.net/browse/HV-1831

this is only a version of https://github.com/hibernate/hibernate-validator/pull/1157 for a main branch with javax->jakarta moved so far.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on licensing, please check here.


marko-bekhta avatar Sep 15 '23 14:09 marko-bekhta

Quality Gate Failed Quality Gate failed

Failed conditions
6.6% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

sonarqubecloud[bot] avatar Oct 17 '24 15:10 sonarqubecloud[bot]

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

I had a look at the numbers but I'm not sure to what I should compare them to? Could you clarify?

gsmet avatar Aug 15 '25 11:08 gsmet

I think I understand them: could you check if in the case with a cycle, we are not consistently slower? I would have expected things to be mostly transparent?

gsmet avatar Aug 15 '25 12:08 gsmet

Also both versions tested include your previous optimization, right?

gsmet avatar Aug 15 '25 12:08 gsmet

Also both versions tested include your previous optimization, right?

yes, all the runs are on top of main, so the previous improvements are already included.

I had a look at the numbers but I'm not sure to what I should compare them to? Could you clarify?

I haven't initially compared to results from main, just predefined/default, as my thought was that the change is really about disabling the tracking ... here are the result from running the benchmark on main:

Benchmark                                                                                                     Mode  Cnt      Score     Error  Units
CascadedWithLotsOfItemsValidation.testCascadedValidationWithLotsOfItems                                      thrpt   20  15547.480 ± 187.809  ops/s
PredefinedScopeCascadedWithLotsOfItemsValidation.testPredefinedScopeCascadedValidationWithLotsOfItems        thrpt   20  16213.816 ± 180.518  ops/s

so with that compared to the case when we disable tracking:

Benchmark                                                                                                     Mode  Cnt      Score     Error  Units
CascadedWithLotsOfItemsValidation.testCascadedValidationWithLotsOfItems                                      thrpt   20  16303.592 ± 205.026  ops/s
PredefinedScopeCascadedWithLotsOfItemsValidation.testPredefinedScopeCascadedValidationWithLotsOfItems        thrpt   20  24974.083 ± 276.476  ops/s

default case matches the results from main (no tracking improvements), and the predefined is much better as we disable tracking entirely there.

let me also run the one with cycles on main too...

marko-bekhta avatar Aug 15 '25 12:08 marko-bekhta

Here are the results for the case with cycles:

main:

Benchmark                                                                                               Mode  Cnt      Score     Error  Units
CascadedWithLotsOfItemsAndCyclesValidation.testCascadedValidationWithLotsOfItems                       thrpt   20  10976.153 ± 139.115  ops/s
PredefinedScopeCascadedWithLotsOfItemsAndCyclesValidation.testCascadedValidationWithLotsOfItems        thrpt   20  10829.914 ± 130.121  ops/s

this patch:

Benchmark                                                                                               Mode  Cnt      Score     Error  Units
CascadedWithLotsOfItemsAndCyclesValidation.testCascadedValidationWithLotsOfItems                       thrpt   20  10850.865 ± 103.808  ops/s
PredefinedScopeCascadedWithLotsOfItemsAndCyclesValidation.testCascadedValidationWithLotsOfItems        thrpt   20  10835.561 ± 100.276  ops/s

It's slower than CascadedWithLotsOfItemsValidation, but I guess the reason is that we have to try to cascade into the object that creates a cycle, and that means at minimum getting the value, which involves reflection and so on.

marko-bekhta avatar Aug 15 '25 13:08 marko-bekhta

Quality Gate Failed Quality Gate failed

Failed conditions
9.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

sonarqubecloud[bot] avatar Aug 22 '25 15:08 sonarqubecloud[bot]

Congrats @marko-bekhta ! This is awesome work!

gsmet avatar Aug 22 '25 16:08 gsmet

thanks @gsmet 🥳🙂! I'll try to get a few more things merged and maybe do an alpha 9.1 some time next week 🤞🏻 🙂

marko-bekhta avatar Aug 22 '25 16:08 marko-bekhta