notfilippo commented on issue #391:
URL: 
https://github.com/apache/datasketches-rust/issues/391#issuecomment-7081354338

   Thanks for the context, both! I was curious how much this actually costs, so 
I tried a few variants on a Ballista-like setup: one HLL8 sketch at lg_k 12, 
built from 1M ClickBench rows in 8,192-row Arrow batches. These are sketch 
builds only, not full queries. CPU time per row, in ns:
   
   | | Int64 UserID, M1 | Int64 UserID, Xeon | URL, M1 | URL, Xeon |
   | --- | ---: | ---: | ---: | ---: |
   | `create_hashes` + `update(hash)` (what #2868 does) | 4.5 | 9.8 | 12.1 | 
26.3 |
   | downcast + `update(value)` | 3.8 | 7.9 | 22.5 | 39.3 |
   | downcast + `update_with_coupons` (#402) | 3.0 | 5.3 | 21.9 | 38.2 |
   | `create_hashes` + `from_hash` | 1.4 | 3.4 | 9.0 | 19.9 |
   
   For integers, downcasting is already faster than going through 
`create_hashes`, even with today's `update`. For long strings it's the other 
way around: Murmur3 costs about twice as much as DataFusion's hash on ~90-byte 
URLs. Short strings came out about even.
   
   And yes, `from_hash` would win everywhere. I checked whether that's because 
foldhash is a weaker hash, and it isn't: the estimates were just as accurate as 
with Murmur3. What worries me is that the bytes don't say which hash built 
them. A `from_hash` sketch looks exactly like any other DataSketches HLL, so if 
it ever meets a normal one, you get a wrong answer and no error. Merging the 
two over the same 1M UserIDs (about 80k distinct) gave me 162k. #2868 is in the 
same spot today, since `update(hash)` hashes DataFusion's hash (merged with a 
normal sketch, I got 158k). And DataFusion has already switched its HLL hash 
once (apache/datafusion#20958), so even Ballista-only sketches could stop 
merging across an upgrade.
   
   I also tried SIMD for the integer hash. With AVX-512 it gets down to 3.8 ns 
per row on the Xeon, but AVX2 barely helped, and NEON and `std::simd` were 
slower than plain code. So I don't think it's worth a library API yet.
   
   So I think it comes down to what Ballista needs from these sketches. If they 
should be real DataSketches HLLs that merge with other implementations and 
survive upgrades, downcasting is the way to go: `update` today, 
`update_with_coupons` once #402 lands, and `raw_bytes::from_str` for strings. 
If they only ever live inside one Ballista version, the DataSketches format 
doesn't buy much, and a sketch that owns its hash would be faster.


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