pingora icon indicating copy to clipboard operation
pingora copied to clipboard

Slight performance boost in `pingora-limit::Estimator`

Open atamakahere-git opened this issue 1 year ago • 2 comments

I was tinkering with the code, to my surprise I made Estimator run faster just by using iterators instead of for-loops

The overall diff is about 60% faster on single thread

Pingora Estimator single thread 2.334566806s total, 23ns avg per operation

vs

Pingora Estimator single thread 868.937015ms total, 8ns avg per operation

There is 2ns gain per thread, from 25ns -> 23ns (8%).

I have attached the complete bench diff for my machine: https://www.diffchecker.com/9EnuDEot/

I may be missing/ignoring something here, cause this is too good to be true.

Though this is a documented and tested behavior.

I have also added a test for reset method, which might be redundant.

atamakahere-git avatar Feb 28 '24 22:02 atamakahere-git

Hey @fee1-dead , I applied your suggested changes, and it seems like .min() is loosing performance compared to .fold(). Can you run the benchmark and tell if that's the same case on other machines too?

atamakahere-git avatar Mar 04 '24 06:03 atamakahere-git

I don't have much time to run benchmarks myself, but I can trust the results. fold doesn't look that bad stylistically when compared to min.

fee1-dead avatar Mar 04 '24 13:03 fee1-dead

This has been merged to the main branch. Thank you for contributing!

gumpt avatar Apr 19 '24 22:04 gumpt