tisonkun opened a new pull request, #353:
URL: https://github.com/apache/datasketches-rust/pull/353

   ### Summary
   
   `CpcUnion::serialize` previously delegated `UnionState::BitMatrix` to 
`self.to_sketch().serialize()`, allocating an intermediate `CpcSketch` 
(`sliding_window` + open-addressed `PairTable`), unpacking and sorting a 
`Vec<u32>` of coupon pairs, encoding into an undersized temporary `payload` 
buffer, and copying that payload behind the preamble.
   
   * Add `serialize_compressed` in `cpc::serialization` and a streaming 
`PairEncoder` in `cpc::compression` so both `CpcSketch::serialize` and 
`CpcUnion::serialize` write the preamble, compressed window, and Golomb-coded 
pairs directly into a single pre-sized output buffer and patch `table_words` / 
`window_words` in place.
   * Generalize `encode_window` to accept `impl IntoIterator<Item = u8>` so 
`CpcUnion` streams window bytes directly from `matrix` words without allocating 
a `Vec<u8>` window.
   * Stream coupon pairs directly from `UnionState::BitMatrix` in ascending 
row-major order with zero intermediate heap allocations: `Sparse` / `Hybrid` 
and `Pinned` rows already yield strictly ordered `(row, col)` pairs without 
sorting, while `Sliding` sorts permuted surprise columns within each 
multi-surprise row on a 56-byte stack array.
   * Extend CPC union integration tests across all flavors (`Empty`, `Sparse`, 
`Hybrid`, `Pinned`, and `Sliding`), custom seeds, downstream merges, and 
mixed-`lg_k` downsampling, and expand `cpc::serde::serialize_union` benchmarks 
to cover `Pinned` and `Sliding` bit-matrix unions.
   
   ### Benchmarks
   
   Measured across 5 interleaved single-run executions (`cargo x bench -- 
cpc::serde --runs 1 --raw`, median and `min..max` over 5 runs) on Apple M4 Max 
(macOS 26.6.2, `rustc 1.101.0-nightly (8006091eb 2026-10-17)`), comparing 
`9de0bbe` (with the matching 5-case benchmark suite) against `e8404d0`:
   
   | Benchmark                             | Flavor / Input                     
| Rounds    | `9de0bbe` median (`min..max`) | `e8404d0` median (`min..max`) | 
Speedup (`vs base`) | `e8404d0` vs `to_sketch().serialize()` |
   | ------------------------------------- | ---------------------------------- 
| --------- | ----------------------------- | ----------------------------- | 
------------------- | -------------------------------------- |
   | `cpc::serde::serialize_union/0`       | `Empty` (`lg_k = 18`)              
| 4,000,000 | 62 ms (`61..65`)              | 58 ms (`57..60`)              | 
`0.94x`             | `0.83x` (vs 70 ms)                     |
   | `cpc::serde::serialize_union/20000`   | `Sparse` (`lg_k = 18`)             
| 500       | 98 ms (`95..103`)             | 94 ms (`91..94`)              | 
`0.96x`             | `0.98x` (vs 96 ms)                     |
   | `cpc::serde::serialize_union/80000`   | `Hybrid` matrix (`lg_k = 18`)      
| 200       | 149 ms (`146..152`)           | 89 ms (`89..100`)             | 
`0.60x`             | `0.58x` (vs 153 ms)                    |
   | `cpc::serde::serialize_union/400000`  | `Pinned` matrix (`lg_k = 18`)      
| 500       | 222 ms (`216..225`)           | 196 ms (`187..199`)           | 
`0.88x`             | `0.88x` (vs 223 ms)                    |
   | `cpc::serde::serialize_union/2500000` | `Sliding` matrix (`lg_k = 18`)     
| 400       | 267 ms (`257..270`)           | 226 ms (`222..234`)           | 
`0.85x`             | `0.86x` (vs 264 ms)                    |
   | `cpc::serde::serialize/200`           | `CpcSketch` `Sparse` (`lg_k = 11`) 
| 400,000   | 349 ms (`346..380`)           | 339 ms (`339..365`)           | 
`0.97x`             | -                                      |
   | `cpc::serde::serialize/8000`          | `CpcSketch` `Sliding` (`lg_k = 
11`)| 500,000   | 353 ms (`345..359`)           | 295 ms (`292..297`)           
| `0.84x`             | -                                      |
   
   Closes #319
   


-- 
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]

Reply via email to