-
Notifications
You must be signed in to change notification settings - Fork 101
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
Use varint gem to speed up decoding? #268
Comments
A few changes that might help a little:
|
That does help kind of, but not by any appreciable amount when I tested compared to replacing it with C. You're describing is what ruby-protocol-buffers does, which I tested as well: def decode(io)
int_val = 0
shift = 0
loop do
raise(DecodeError, "too many bytes when decoding varint") if shift >= 64
byte = io.getbyte
int_val |= (byte & 0b0111_1111) << shift
shift += 7
return int_val if (byte & 0b1000_0000) == 0
end
end I also tried replacing |
would be interested in a Varint PR that still allows the pure ruby version to be usable without any hacks; our primary deployment VM is JRuby which is why we make so many "pure ruby" updates |
Yup no problem, we have JRuby apps as well. I'll whip up a PR tomorrow. |
The protobuf gem https://github.com/codekitchen/ruby-protocol-buffers has a C extension called varint. If you take a look at a trace after the enum fix is applied
That's the top time spent on decoding. It's super easy to patch this in if the gem is available
This is something that could be offered automatically if the gem is available, it patches it in otherwise it just uses pure Ruby. I understand if you'd rather not include this, since it's a third party C library. If you're interested, I can wrap this up into a PR. Using it resulted in a 25% speedup.
The text was updated successfully, but these errors were encountered: