Repository navigation
perf: Countmin performance improvements #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| use datasketches::countmin::CountMinSketch; | ||
| use datasketches::hash::value::raw_bytes; | ||
| use divan::Bencher; | ||
| use divan::black_box; | ||
| use divan::counter::ItemsCount; | ||
|
|
||
| use crate::hash_inputs::ITEMS; | ||
| use crate::hash_inputs::bytes_32_values; | ||
|
|
||
| #[divan::bench] | ||
| fn u64(bencher: Bencher) { | ||
| let mut sketch = CountMinSketch::<u64>::new(4, 16_384).unwrap(); | ||
| for value in 0..ITEMS as u64 { | ||
| sketch.update(value); | ||
| } | ||
|
|
||
| bencher.counter(ItemsCount::new(ITEMS)).bench_local(|| { | ||
| let mut total = 0u64; | ||
| for value in 0..ITEMS as u64 { | ||
| total = total.wrapping_add(sketch.estimate(black_box(value))); | ||
| } | ||
| black_box(total) | ||
| }); | ||
| } | ||
|
|
||
| #[divan::bench] | ||
| fn bytes_32(bencher: Bencher) { | ||
| let values = bytes_32_values(); | ||
| let mut sketch = CountMinSketch::<u64>::new(4, 16_384).unwrap(); | ||
| for value in &values { | ||
| sketch.update(raw_bytes::from_slice(value)); | ||
| } | ||
|
|
||
| bencher.counter(ItemsCount::new(ITEMS)).bench_local(|| { | ||
| let mut total = 0u64; | ||
| for value in &values { | ||
| total = total.wrapping_add(sketch.estimate(raw_bytes::from_slice(black_box(value)))); | ||
| } | ||
| black_box(total) | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,5 @@ | |
| // under the License. | ||
|
|
||
| mod decay; | ||
| mod estimate; | ||
| mod update; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this perf improvement subtly change the estimation but still within the margin of error? I think we may assert against the range.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have reviewed the logic here, and found that: The reduction is exact, not approximate: fast_remainder and the power-of-two mask both return exactly what % returned, so bucket placement, estimates, and error bounds are bit-for-bit unchanged.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the review, yes the intent is that it will give the same result as before
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops. This is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally find this field name strange, but I cannot find a better alternative.
I can live with it anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/apache/datasketches-rust/pull/301/changes#r4365448625