Skip to content

Conversation

pgimalac
Copy link

@pgimalac pgimalac commented Feb 28, 2024

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

@CLAassistant
Copy link

CLAassistant commented Feb 28, 2024

CLA assistant check
All committers have signed the CLA.

@pgimalac
Copy link
Author

pgimalac commented Jun 4, 2024

@manishrjain @jarifibrahim any chance to get a review ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants