-
Notifications
You must be signed in to change notification settings - Fork 10
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
Hot path optimizations #25
base: main
Are you sure you want to change the base?
Conversation
float_buckets = | ||
buckets | ||
|> Enum.map(&(&1 * 1.0)) | ||
|> Enum.with_index() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use with_index/2
and do it once, but please double check the Elixir version support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is executed in compile time so I wouldn't worry too much about it
Co-authored-by: José Valim <[email protected]>
Thank you for your contribution! This PR made me curious, as I thought that Erlang's function head pattern matching was about as fast as it gets, and that it does binary search on arguments where appropriate, using Erlang's term ordering. For a small number of buckets (i.e. using Peep.Buckets.PowersOfTen), the current implementation and your implementation have similar performance, or the difference was indistinguishable in my benchmarking. However, with 1000 buckets (the maximum I was able to stuff into a single module), your implementation's p99 latency is only 1/3rd that of the current implementation, which is a great improvement! Given that your Peep.Buckets.Custom implementation appears to always be at least as fast as the current implementation, it seems there's no downside to accepting your contribution. I've fallen a bit behind on reviewing contributions here, but I intend to carefully review and address the current set of open PRs in the coming days. |
Access
, compiler option for inlining, map destructurisation