Commit f646566
authored
perf: Avoid throwing ValidationExceptions in happy flow (#50)
* fix: Add missing extensions arg to constructors in new coercion tests
Tests added in the JSON Schema type-coercion fix used the pre-extensions
record signatures and stopped compiling after the OpenAPI extensions
feature merged into master.
* perf: Replace exception-driven control flow in DefaultValidator with Optional returns
JFR profiling under load showed ~267 ValidationException throws/sec on
the happy path — oneOf/anyOf branch selection was catching exceptions
to determine which branch matched, paying allocation + stack-walk cost
for every non-matching branch even when the request ultimately succeeded.
Internal validation now returns Optional<ValidationError> and branch
selection inspects the result. ValidationException is constructed at
most once per request, only at the public validate() boundary when
real validation has failed. A static counter on ValidationException
makes the contract observable and testable.1 parent b091058 commit f646566
3 files changed
Lines changed: 267 additions & 132 deletions
File tree
- src
- main/java/com/retailsvc/http
- validate
- test/java/com/retailsvc/http/validate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
6 | 14 | | |
7 | 15 | | |
8 | 16 | | |
9 | 17 | | |
10 | 18 | | |
| 19 | + | |
11 | 20 | | |
12 | 21 | | |
13 | 22 | | |
| |||
0 commit comments