Waterpine commented on PR #330: URL: https://github.com/apache/datasketches-rust/pull/330#issuecomment-6787695748
> @Waterpine I reproduced a silent false negative when an existing wasm32 filter is read after upgrading to this PR. Please keep the old mapping here and handle the compatibility correction separately with a migration plan. > > This was introduced in **[`7615853`](https://github.com/apache/datasketches-rust/commit/7615853585b1e55870cdb1b40d34a6fb8913a014)**: [`compute_bit_index`, line 650](https://github.com/apache/datasketches-rust/blob/7615853585b1e55870cdb1b40d34a6fb8913a014/datasketches/src/bloom/sketch.rs#L650) removes the `as usize` before the right shift. The earlier optimization (`4f5253c`) preserved it. On 32-bit targets, this changes the input from a truncated hash to the full `u64`. > > Both the new reduction algorithm and the `write_u64` optimization can stay. Restore the original truncation before passing the hash to the reducer: > > ```rust > let hash = h0.wrapping_add(u64::from(i).wrapping_mul(h1)) as usize; > self.reducer.remainder((hash >> 1) as u64) as usize > ``` > > **Minimal reproduction:** the bytes below were generated by `4ba130e` on wasm32 using `BloomFilterBuilder::with_size(192, 3).seed(9001).build()`, then inserting `0u64`. In actual wasm32 builds run in Node, the base reads this item successfully; the PR head fails the assertion. Enable the `bloom` feature: > > ```rust > use datasketches::bloom::BloomFilter; > > fn main() { > let hex = "0401150003000000292300000000000003000000000000000300000000000000000808040000000000000000000000000000000000000000"; > let bytes: Vec<u8> = (0..hex.len()) > .step_by(2) > .map(|i| u8::from_str_radix(&hex[i..i + 2], 16).unwrap()) > .collect(); > > let filter = BloomFilter::deserialize(&bytes).unwrap(); > assert!(filter.contains(&0u64)); // Fails on the PR head. > } > ``` > > The reverse direction also fails on rollback. Old and new filters still pass `is_compatible`, so mixing them also silently breaks set operations. Re-serialization does not repair the mapping. > > ### About splitting the hashing change > Splitting the hashing optimization into a separate PR is fine and would make its validation easier to review, but I do not require a split. Keeping it here is also fine. Thanks for catching this and for the reproduction. I've restored the `usize` conversion as you suggested (40c9066), so bit placement is unchanged on every target, and the unit test compares against the original expression again. I have no wasm32 runtime here, so I couldn't rerun your reproduction; the code is the form you suggested. The description no longer claims the 32-bit change; the 32-bit correction is left for a separate change with a migration plan. I'll keep the hashing change in this PR, since the measurements cover the combination. `main` is merged in to resolve the conflict with #340. -- 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]
