Skip to content
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

Stop pre-computing log2 values in allocator.go #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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