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

Optimize the mod operation #96

Closed
wants to merge 1 commit into from
Closed

Optimize the mod operation #96

wants to merge 1 commit into from

Conversation

chenquan
Copy link

@chenquan chenquan commented Apr 9, 2021

Optimizing mod operation with bit operation

@chenquan
Copy link
Author

@orcaman Maybe you can have a look?

@orcaman
Copy link
Owner

orcaman commented Apr 11, 2021

Thanks, you @chenquan, I learned a few things reading more about this type of optimization!

I would expect that the Go compiler apply these types of optimizations under the hood. Did you check if this change actually improves performance? It would be cool to include a benchmark to see if this actually moves the needle.

@orcaman
Copy link
Owner

orcaman commented May 2, 2021

BTW, modulo of powers of 2 can alternatively be expressed as a bitwise AND operation, but not for all numbers. Since the number of shards is an easy-to-change constant, this might cause users of this repo issues if they are not aware). Anyway thanks for this

@orcaman orcaman closed this May 2, 2021
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