You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
uniqueItems: comparisonKey allocations slow down validation of all arrays (master and 2.x) #1302
#1273 (master) and its backport #1301 (2.x) changed UniqueItemsValidator to compare items by comparisonKey. That fixed numeric equality ([1, 1.0] is now a duplicate), but every array now pays for it, not just arrays that mix integers and decimals:
every number gets a new BigDecimal from decimalValue().stripTrailingZeros();
every nested array or object is deep-copied into an ArrayList/LinkedHashMap key.
Rough timing on Java 8 against 2.x, with schema {"uniqueItems":true}, 20 warm-up runs, then the average of 20:
Instance
Before (node equality)
After (comparisonKey)
200k ints
1.8 ms
7.9 ms
20k objects, 10 string fields each
3.3 ms
6.7 ms
master uses the same design, so it should behave the same way.
Possible approaches:
Use a cheaper key for numbers: Long.valueOf(longValue()) for integral nodes that fit in a long, and the stripped BigDecimal only for the other numbers, mapped to Long when it's integral and fits. Integers and decimals with the same value still collide.
Or don't copy containers: wrap each node in a small key object whose equals/hashCode walk the node and compare numbers by value. That avoids allocating a copy of each nested array or object.
The fix needs to:
keep the numeric-equality rules (UniqueItemsNumericEqualityTest) and the JSON-Schema-Test-Suite passing (numbers stay distinct from booleans and strings);
Two smaller items from the #1301 review were deferred here. Both apply to master and 2.x, so please fix them on both branches along with the speed work:
A test that passes without the fix.UniqueItemsNumericEqualityTest.decimalsWithDifferentScaleAreDuplicates ([1.0, 1.00]) passes with or without numeric folding. The default mapper reads both values as the same DoubleNode(1.0), so they were already equal as nodes. To make it test scale-independence, read the instance with USE_BIG_DECIMAL_FOR_FLOATS so the two values stay as BigDecimals with different scales.
Javadoc indentation. In the comparisonKey Javadoc in UniqueItemsValidator, the lines starting * of that and keep comparing as nodes and * Only numbers are folded together lost their leading indentation.
Activity
stevehu commentedon Oct 12, 2026
Two smaller items from the #1301 review were deferred here. Both apply to
masterand2.x, so please fix them on both branches along with the speed work:UniqueItemsNumericEqualityTest.decimalsWithDifferentScaleAreDuplicates([1.0, 1.00]) passes with or without numeric folding. The default mapper reads both values as the sameDoubleNode(1.0), so they were already equal as nodes. To make it test scale-independence, read the instance withUSE_BIG_DECIMAL_FOR_FLOATSso the two values stay asBigDecimals with different scales.comparisonKeyJavadoc inUniqueItemsValidator, the lines starting* of that and keep comparing as nodesand* Only numbers are folded togetherlost their leading indentation.ItsDeadlyProgrammer commentedon Oct 12, 2026
I'll take this, along with the two items from the #1301 review. I'll open a PR for
masterand one for2.x, with before/after timings.Compare uniqueItems items without copying them (#1305)
[2.x] Compare uniqueItems items without copying them (#1306)