ruby-protobuf / protobuf

A pure ruby implementation of Google's Protocol Buffers
https://github.com/ruby-protobuf
MIT License
463 stars 101 forks source link

Small optimizations #308

Closed film42 closed 7 years ago

film42 commented 8 years ago

This just adds a few speedups.

  1. class_eval string - This turned out to be about 40% faster for setters and 48% faster for getters (for both MRI and Jruby). Here's my benchmark: https://gist.github.com/film42/8efd4810d3c5a5e12291.
  2. Varint - This takes the optimized varint out of https://github.com/ruby-protobuf/protobuf/pull/297.
  3. nonzero? vs != 0 - Declarative methods are nice, but simple operators are still very readable and more performant, especially in these hot code paths.

Note: I also added benchmark-ips as a dev dependency because I end up using it a lot when working with protobuf.

cc @abrandoned @zachmargolis @embark

embark commented 8 years ago

:+1: seems good, though I prefer the hex unless it's slower :)

zachmargolis commented 8 years ago

Seems legit, LGTM :+1:

mmmries commented 8 years ago

:+1: this looks good to me. No strong preference on hex vs dec.

abrandoned commented 8 years ago

@film42 were we going to pull this in? looks like it needs to be updated if so

film42 commented 8 years ago

Still planning on it, but working through getting 3.7.0 features into master first, then coming back and doing a full profile again.