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

Abrandoned/decoding setters without copy #297

Open abrandoned opened 8 years ago

abrandoned commented 8 years ago

start moving towards per field decoding setters instead of using the standard setter during the decode routine; the standard setter does copies to keep from mutating an incoming value when a value is set, during decode we also make a copy as a result of pulling it off the stream, largely reduces a single copy and in cases where we can it prevents the acceptable? checks as a value that has been serialized and is tagged should be acceptable

also started added setters directly on the message object by tag instead of doing a field lookup and then running through the name of the field; reduces the amount of searching for field definitions and will eventually lead to us having a deserialization routine that only utilizes tags (instead of field lookup)

on MRI and JRuby these changes accounted for ~20% decrease in time for serialization/deserialization of the command bx rake benchmark:profile_protobuf_serialize[100000,prof_out.txt]

@film42

abrandoned commented 8 years ago

@zachmargolis would love to get your thoughts on this path

embark commented 8 years ago

:+1: great optimization!

How much benefit do we get on creating the dynamic per-tag methods vs. having 1 method in the message where that requires a field lookup first?

Just curious if the optimization is worth the complexity tradeoff of a bunch of new dynamically generated methods