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 Varint encoding #60

Merged
merged 1 commit into from Jun 20, 2022
Merged

Optimize Varint encoding #60

merged 1 commit into from Jun 20, 2022

Conversation

bugadani
Copy link
Contributor

This PR optimizes the varint_* functions to avoid an unnecessary bit masking.

The idea behind this PR is the following:

  • Iteration stops if (value >>= 7) == 0, in which case value < 128. In this case, the 0x7F masking isn't necessary.
  • If value > 128 we want to set the highest bit of the extracted byte to 1. In this case, the 0x7F masking isn't necessary, because we overwrite the masked bit anyway.

Assuming I'm not catastrophically wrong, the resulting code optimizes slightly better: https://rust.godbolt.org/z/8dz48vocx

@netlify
Copy link

netlify bot commented Jun 20, 2022

Deploy Preview for cute-starship-2d9c9b ready!

Name Link
🔨 Latest commit 09b00c8
🔍 Latest deploy log https://app.netlify.com/sites/cute-starship-2d9c9b/deploys/62b0958843924f0008744cc1
😎 Deploy Preview https://deploy-preview-60--cute-starship-2d9c9b.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@jamesmunns
Copy link
Owner

Looks great, thanks!

@jamesmunns jamesmunns merged commit 2edf154 into jamesmunns:main Jun 20, 2022
@bugadani bugadani deleted the opt branch June 20, 2022 16:24
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.

None yet

2 participants