ristretto
ristretto copied to clipboard
Stop pre-computing log2 values in `allocator.go`
Pre-computing the log2 values of integers until 1024 in a global slice in an init function takes around 1ms on AWS Lambda environment, and causes around 10kB of allocations.
Removing the global slice and pre-computing entirely, as well as the custom computing of log2 in favor of using the std lib bits.Len function, removes this unneeded overhead, and is actually faster.
Benchmark
I ran a quick benchmark on both versions on my laptop, they had similar performance for numbers below 1024 (around 2ns / op), and using random integers the previous version took an average 23ns / op while the new version was still 2ns / op.
@manishrjain @jarifibrahim any chance to get a review ?