jungm opened a new pull request, #272: URL: https://github.com/apache/bval/pull/272
Removes repeated lookups that every `validate()` call performed. - **Results:** violations are collected in plain fields instead of `Lazy` holders. This also keeps `ValidationJob#getResults()` small enough for C2 to inline, so validating a bean with nothing to check allocates nothing. Without it, the next commit pushes `getResults()` past C2's inline size limit and the no-constraints path drops about 57% (0 → 88 B/op). - **Bean descriptors:** they are cached by the runtime (possibly proxy) class of the validated object, so resolving one takes a single map lookup. A cache hit no longer writes to a `ConcurrentHashMap`, and the root descriptor is resolved once per validation. - **Groups:** `Groups#asStrategy()`, group strategy hash codes, and the groups computed for a single explicit group are cached. - **Property reads:** values are read through cached `MethodHandle`s. `Field#get`/`Method#invoke` take a slow path when the reflective object is not a JIT constant. Reflection remains the fallback, with the same exception wrapping. - **Validators:** each constraint's initialized validator is memoized on its descriptor, and cached unwrapping information is looked up before going through `computeIfAbsent`. Biggest effects: `Jsr303Benchmark.bvalNoConstraints` 2.2×, `validateProperty` 2×, `explicitGroup` 1.3×. Allocation drops 5–20% across scenarios. The `Jsr303Benchmark.bvalBuildFactory`/`bvalBootstrapAndValidate` drops are noise: allocation is unchanged, and they recover in the PRs above. ### Benchmarks (vs. #PREV) Measured with JMH 1.37 on JDK 25 (`-p provider=bval -f 2 -wi 2 -i 3`, 1 s iterations, `-prof gc`) against the PR below this one in the stack. This was a busy desktop machine, so throughput carries large error bars (shown as ±). The allocation column (B/op) is deterministic and more reliable. | Benchmark | Before | After | Change | B/op before → after | |---|---:|---:|---:|---:| | cascadedCycles (ops/ms) | 2.30 ± 12% | 2.42 ± 14% | **1.05×** | 1,259,572 → 1,202,427 | | cascadedList (ops/ms) | 0.47 ± 15% | 0.32 ± 33% | **0.67×** | 6,110,831 → 5,778,430 | | classLevelInvalid (ops/ms) | 683 ± 21% | 516 ± 61% | **0.76×** | 4,416 → 3,896 | | classLevelValid (ops/ms) | 1,011 ± 16% | 978 ± 68% | **0.97×** | 3,248 → 3,040 | | composedInvalid (ops/ms) | 502 ± 2% | 669 ± 5% | **1.33×** | 5,652 → 4,712 | | composedValid (ops/ms) | 811 ± 13% | 1,042 ± 5% | **1.28×** | 3,172 → 2,976 | | containerElements (ops/ms) | 1.66 ± 7% | 1.84 ± 19% | **1.11×** | 1,681,221 → 1,623,248 | | deepGraph (ops/ms) | 90.9 ± 10% | 87.9 ± 68% | **0.97×** | 32,275 → 31,289 | | elMessage (ops/ms) | 696 ± 15% | 657 ± 99% | **0.94×** | 4,196 → 3,840 | | executableParameters (ops/ms) | 424 ± 21% | 532 ± 10% | **1.26×** | 6,211 → 5,761 | | executableReturnValue (ops/ms) | 388 ± 19% | 496 ± 12% | **1.28×** | 6,841 → 6,255 | | explicitGroup (ops/ms) | 577 ± 6% | 734 ± 11% | **1.27×** | 5,757 → 4,930 | | mixedDrivers (ops/ms) | 353 ± 70% | 536 ± 27% | **1.52×** | 5,848 → 5,422 | | validateProperty (ops/ms) | 1,010 ± 64% | 2,026 ± 4% | **2.01×** | 2,027 → 1,795 | | validateValue (ops/ms) | 2,109 ± 40% | 2,479 ± 45% | **1.18×** | 1,325 → 1,070 | | wideBeanInvalid (ops/ms) | 59.2 ± 30% | 68.1 ± 44% | **1.15×** | 31,759 → 28,157 | | wideBeanValid (ops/ms) | 134 ± 41% | 72.0 ± 92% | **0.54×** | 17,553 → 17,308 | | Jsr303Benchmark.bvalBootstrapAndValidate (ops/s) | 2,844 ± 48% | 1,652 ± 61% | **0.58×** | 245,596 → 250,395 | | Jsr303Benchmark.bvalBuildFactory (ops/s) | 11,275 ± 3% | 3,164 ± 43% | **0.28×** | 87,993 → 89,026 | | Jsr303Benchmark.bvalConstraintsFailure (ops/s) | 590,674 ± 16% | 471,733 ± 46% | **0.80×** | 5,520 → 5,000 | | Jsr303Benchmark.bvalConstraintsFailureReuseValidator (ops/s) | 607,050 ± 8% | 514,364 ± 60% | **0.85×** | 5,520 → 5,048 | | Jsr303Benchmark.bvalConstraintsSuccess (ops/s) | 1,001,414 ± 37% | 826,895 ± 91% | **0.83×** | 3,212 → 3,068 | | Jsr303Benchmark.bvalConstraintsSuccessReuseValidator (ops/s) | 936,769 ± 49% | 1,133,176 ± 70% | **1.21×** | 3,248 → 3,080 | | Jsr303Benchmark.bvalNoConstraints (ops/s) | 71,836,297 ± 29% | 159,318,160 ± 10% | **2.22×** | 0 → 0 | | Jsr303Benchmark.bvalNoConstraintsReuseValidator (ops/s) | 119,638,823 ± 13% | 147,841,169 ± 67% | **1.24×** | 0 → 0 | -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
