notfilippo opened a new pull request, #402: URL: https://github.com/apache/datasketches-rust/pull/402
`HllSketch::update_with_coupons` takes an iterator of coupons and applies them in order. It produces the same estimates, confidence bounds, and serialized bytes as calling `update_with_coupon` for each coupon. Callers can hash values as they go without allocating a coupon buffer: ```rust sketch.update_with_coupons(values.iter().copied().map(Coupon::from_value)); ``` Once the sketch becomes dense, it selects the register format once for the rest of the batch. HLL8 also reuses the register mask and estimator reference across updates. ### Why keep HIP? I also tried a batch update that discarded HIP (historical inverse probability) and deferred estimator work until the next read. To compare the two approaches, I replayed ClickBench Q4 on an M1 Max. Each replay fed one million decoded `UserID` values to a fresh accumulator in batches of 8,192. Hashing and the final estimate are included; Parquet reads and SQL execution are not. The DataSketches variants all used HLL8 with `lg_k = 14`. | Accumulator | Shard 0, 154 replays | Shard 37, 168 replays | |---|---:|---:| | DataFusion `approx_distinct` | 380 [379, 393] | 380 [377, 396] | | DataSketches, one `update` per value | 696 [689, 714] | 806 [788, 855] | | **`update_with_coupons` (this PR)** | **556 [547, 561]** | **644 [634, 672]** | | Batch discarding HIP (experiment only) | 511 [506, 524] | 561 [550, 593] | Times are median thread CPU milliseconds [min, max] over 12 interleaved runs. The ordered batch used about 20% less CPU than scalar updates on both shards, and their serialized sketches matched after every batch. Discarding HIP saved another 7% and 13% in the paired runs, but changed what `estimate()` returns. On shard 0, for example, the same final registers gave 80,104 with HIP and 80,053 with the composite estimator. Once HIP is discarded, later estimates and confidence bounds use the composite estimator instead. This PR keeps the ordered speedup without asking callers to make that trade. The in-tree benchmark isolates scalar vs. batch updates with precomputed coupons: `cargo x bench -- hll::update::precomputed_coupons`. Related: #385. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
