-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Save memory on histograms: slightly faster with less code #536
Conversation
* one allocation for duo instantiations * use index overflow instead of redundant last state field name old time/op new time/op delta HistogramWithLabelValues-12 204ns ± 0% 204ns ± 0% ~ (all equal) HistogramNoLabels-12 41.1ns ± 0% 40.5ns ± 0% ~ (p=1.000 n=1+1) HistogramObserve1-12 33.1ns ± 0% 33.9ns ± 0% ~ (p=1.000 n=1+1) HistogramObserve2-12 132ns ± 0% 122ns ± 0% ~ (p=1.000 n=1+1) HistogramObserve4-12 377ns ± 0% 364ns ± 0% ~ (p=1.000 n=1+1) HistogramObserve8-12 1.00µs ± 0% 0.96µs ± 0% ~ (p=1.000 n=1+1) HistogramWrite1-12 1.80µs ± 0% 1.76µs ± 0% ~ (p=1.000 n=1+1) HistogramWrite2-12 3.28µs ± 0% 3.25µs ± 0% ~ (p=1.000 n=1+1) HistogramWrite4-12 6.66µs ± 0% 6.66µs ± 0% ~ (p=1.000 n=1+1) HistogramWrite8-12 13.7µs ± 0% 13.6µs ± 0% ~ (p=1.000 n=1+1) name old alloc/op new alloc/op delta HistogramWithLabelValues-12 48.0B ± 0% 48.0B ± 0% ~ (all equal) HistogramNoLabels-12 0.00B 0.00B ~ (all equal) name old allocs/op new allocs/op delta HistogramWithLabelValues-12 1.00 ± 0% 1.00 ± 0% ~ (all equal) HistogramNoLabels-12 0.00 0.00 ~ (all equal) Signed-off-by: Pascal S. de Kloe <[email protected]>
Note: The test failure is unrelated to this PR. It's caused by a Travis change, which I'll take care of separately. |
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.
Thanks for your contribution. Making the most significant bit the index bit simplifies things a lot. I really like the idea. The actual performance improvements appear very close to noise, but the code becomes cleaner (if "clean" can ever be an appropriate attribute if doing this kind of bit mangling).
On the other hand, I'm not convinced about the allocation optimizations in the constructor function. It's not really in the hot path, and it makes the code less clean.
If you rebase this on master, it should make the test green. |
Signed-off-by: Pascal S. de Kloe <[email protected]>
Signed-off-by: Pascal S. de Kloe <[email protected]>
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.
Thanks again.
I've borrowed some of your thinking so this is fair-trade. 😁 |
Signed-off-by: beorn7 <[email protected]>
name old time/op new time/op delta
HistogramWithLabelValues-12 204ns ± 0% 204ns ± 0% ~ (all equal)
HistogramNoLabels-12 41.1ns ± 0% 40.5ns ± 0% ~ (p=1.000 n=1+1)
HistogramObserve1-12 33.1ns ± 0% 33.9ns ± 0% ~ (p=1.000 n=1+1)
HistogramObserve2-12 132ns ± 0% 122ns ± 0% ~ (p=1.000 n=1+1)
HistogramObserve4-12 377ns ± 0% 364ns ± 0% ~ (p=1.000 n=1+1)
HistogramObserve8-12 1.00µs ± 0% 0.96µs ± 0% ~ (p=1.000 n=1+1)
HistogramWrite1-12 1.80µs ± 0% 1.76µs ± 0% ~ (p=1.000 n=1+1)
HistogramWrite2-12 3.28µs ± 0% 3.25µs ± 0% ~ (p=1.000 n=1+1)
HistogramWrite4-12 6.66µs ± 0% 6.66µs ± 0% ~ (p=1.000 n=1+1)
HistogramWrite8-12 13.7µs ± 0% 13.6µs ± 0% ~ (p=1.000 n=1+1)
name old alloc/op new alloc/op delta
HistogramWithLabelValues-12 48.0B ± 0% 48.0B ± 0% ~ (all equal)
HistogramNoLabels-12 0.00B 0.00B ~ (all equal)
name old allocs/op new allocs/op delta
HistogramWithLabelValues-12 1.00 ± 0% 1.00 ± 0% ~ (all equal)
HistogramNoLabels-12 0.00 0.00 ~ (all equal)