ristretto icon indicating copy to clipboard operation
ristretto copied to clipboard

Stop pre-computing log2 values in `allocator.go`

Open pgimalac opened this issue 1 year ago • 2 comments

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.


This change is Reviewable

pgimalac avatar Feb 28 '24 21:02 pgimalac

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Feb 28 '24 21:02 CLAassistant

@manishrjain @jarifibrahim any chance to get a review ?

pgimalac avatar Jun 04 '24 20:06 pgimalac