Repository navigation
Hll delay kxq - #364
Merged
Merged
Hll delay kxq#364
Conversation
Pull Request Test Coverage Report for Build 4769907663
💛 - Coveralls |
AlexanderSaydakov
approved these changes
Apr 21, 2023
… over primitive coupons
AlexanderSaydakov
approved these changes
Apr 22, 2023
leerho
added a commit
that referenced
this pull request
Sep 5, 2026
…tants Three independent defects in the HLL estimator state. 1. The deferred KxQ rebuild from #364 still leaves curMin/numAtCurMin merge order dependent. #512 repaired the visible damage, but not the representation the rebuild writes: check_rebuild_kxq_cur_min() stores the true minimum register value and the count at that minimum, while the rest of the HLL_8 code maintains curMin == 0 with numAtCurMin counting the zero registers. When the merged array has no zero register the rebuild leaves curMin > 0, and from then on numAtCurMin -= (curVal == 0) never fires, so the stored pair freezes and drifts away from the registers. Its value depends on when the rebuild fired, hence on merge order. Over 4800 randomized merge-order comparisons 92 differed only in these two fields; the same sweep before #364 gives 0. Estimates and bounds are unaffected because both consumers branch on curMin == 0, so this is a serialization determinism defect. Emit the canonical form instead, and add the HLL_8 / HLL-mode guard that datasketches-java has, so the rebuild can never rewrite curMin on an HLL_4 array whose nibbles are stored relative to it. 2. HLL_HIP_RSE_FACTOR and HLL_NON_HIP_RSE_FACTOR were rounded to seven digits. For lg_k > 12 the bounds use the closed form rather than the interpolation table, so this is observable: the HIP bounds differ from Java by ~4.3e-11 relative and the non-HIP factor is off by 1.7e-6 relative, skewing the bounds of every union result above lg_k 12. Use full precision literals taken from Java's Double.toString output, rather than computing sqrt(log(2.0)) at runtime, so the value cannot vary with the platform libm. 3. harmonicNumber() and getHllBitMapEstimate() called the platform std::log. getBitMapEstimate computes K * (H(K) - H(K - numHit)), whose cancellation amplifies a 1 ULP log difference by about 17x. Apple libm differs from fdlibm on 0.62% of a 400000 sample sweep. Java's StrictMath.log is specified to be fdlibm, so add common/include/fdlibm_log.hpp (FDLIBM 5.3 __ieee754_log, Sun notice preserved) and use it in both places. fdlibm needs strict IEEE evaluation, and the clang pragma is overridden by an explicit -ffp-contract=fast, so the contraction sensitive expressions go through a volatile round trip; verified bit-identical to Java under -O2, -O3, -ffp-contract=on and =fast. This changes serialized bytes, unlike the preceding PR. Union results carry the canonical curMin/numAtCurMin, linear-counting estimates shift ~1e-15, and bounds above lg_k 12 shift as described. Reading is unaffected: older images still deserialize and yield identical estimates and bounds. Adds HllKxqRebuildTest.cpp. Three of the four assertions that also compile against the parent branch fail there and pass here; the fourth already held and is kept as a guard. With the companion datasketches-java change, a 1041 record corpus spanning lg_k 4..21, all three target types, 17 sizes across LIST/SET/HLL, round trips and 80 union scenarios goes from 428 differing records to 0, comparing every serialized byte, estimate, composite estimate and bound as raw IEEE bits. Co-Authored-By: Claude Opus 5 <[email protected]>
leerho
added a commit
that referenced
this pull request
Sep 6, 2026
…tants Three independent defects in the HLL estimator state. 1. The deferred KxQ rebuild from #364 still leaves curMin/numAtCurMin merge order dependent. #512 repaired the visible damage, but not the representation the rebuild writes: check_rebuild_kxq_cur_min() stores the true minimum register value and the count at that minimum, while the rest of the HLL_8 code maintains curMin == 0 with numAtCurMin counting the zero registers. When the merged array has no zero register the rebuild leaves curMin > 0, and from then on numAtCurMin -= (curVal == 0) never fires, so the stored pair freezes and drifts away from the registers. Its value depends on when the rebuild fired, hence on merge order. Over 4800 randomized merge-order comparisons 92 differed only in these two fields; the same sweep before #364 gives 0. Estimates and bounds are unaffected because both consumers branch on curMin == 0, so this is a serialization determinism defect. Emit the canonical form instead, and add the HLL_8 / HLL-mode guard that datasketches-java has, so the rebuild can never rewrite curMin on an HLL_4 array whose nibbles are stored relative to it. 2. HLL_HIP_RSE_FACTOR and HLL_NON_HIP_RSE_FACTOR were rounded to seven digits. For lg_k > 12 the bounds use the closed form rather than the interpolation table, so this is observable: the HIP bounds differ from Java by ~4.3e-11 relative and the non-HIP factor is off by 1.7e-6 relative, skewing the bounds of every union result above lg_k 12. Use full precision literals taken from Java's Double.toString output, rather than computing sqrt(log(2.0)) at runtime, so the value cannot vary with the platform libm. 3. harmonicNumber() and getHllBitMapEstimate() called the platform std::log. getBitMapEstimate computes K * (H(K) - H(K - numHit)), whose cancellation amplifies a 1 ULP log difference by about 17x. Apple libm differs from fdlibm on 0.62% of a 400000 sample sweep. Java's StrictMath.log is specified to be fdlibm, so add common/include/fdlibm_log.hpp (FDLIBM 5.3 __ieee754_log, Sun notice preserved) and use it in both places. fdlibm needs strict IEEE evaluation, and the clang pragma is overridden by an explicit -ffp-contract=fast, so the contraction sensitive expressions go through a volatile round trip; verified bit-identical to Java under -O2, -O3, -ffp-contract=on and =fast. LICENSE gains an FDLIBM entry alongside the existing xxhash64, MurmurHash3 and bithacks entries. This changes serialized bytes, unlike the preceding PR. Union results carry the canonical curMin/numAtCurMin, linear-counting estimates shift ~1e-15, and bounds above lg_k 12 shift as described. Reading is unaffected: older images still deserialize and yield identical estimates and bounds. Adds HllKxqRebuildTest.cpp. Three of the four assertions that also compile against the parent branch fail there and pass here; the fourth already held and is kept as a guard. With the companion datasketches-java change, a 1041 record corpus spanning lg_k 4..21, all three target types, 17 sizes across LIST/SET/HLL, round trips and 80 union scenarios goes from 428 differing records to 0, comparing every serialized byte, estimate, composite estimate and bound as raw IEEE bits. Co-Authored-By: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This changes HLL union to delay recomputing the KxQ and cur_min values until the union gadget needs to be made a consistent sketch (either get_result() or a direct get_estimate() will trigger that). This mirrors how HLL union operates in java.
Using characterization's hll-union-timing test on my linux desktop showed a steady-state merge speed improvement around 2.8x.