Speed Up Creates & Updates By Memoizing on encode#293
Speed Up Creates & Updates By Memoizing on encode#293abrandoned merged 12 commits intoruby-protobuf:masterfrom
Conversation
lib/protobuf/message.rb
Outdated
|
|
||
| ## | ||
| # Attributes | ||
| # |
There was a problem hiding this comment.
why would we need the attr_accessor? (either of them)
lib/protobuf/field/base_field.rb
Outdated
|
|
||
| message_class.class_eval do | ||
| define_method(method_name) do |val| | ||
| @memoized_encoded = nil |
There was a problem hiding this comment.
I think we might want to say @has_change = true. It becomes more clear to me what we're trying to keep track of. That's just my opinion though.
|
@film42 commenting here since the diff you commented on got deleted. But yeah, I think But the goal here it to clear out that instance variable so that when we hit the memoization in the |
|
@vintagepenguin It would be more clear set a flag, or call a Looks like you have a 👮 to fix, but then |
Speed Up Creates & Updates By Memoizing on encode
|
It seems that with this change, performing operations on repeated fields is no longer handled properly after the memoized encoding has been computed. a.encode
a.some_repeated_field << "new-value"
a.encode # doesn't contain "new-value" |
|
That's definitely a problem, @goddardc. Mind writing up an issue? |
|
@liveh2o Sure thing! |
Serialization is one of the slowest things that you do in Protobuf. If we already have an encoded message, then we don't need to encode it again so why not memoize it.
@abrandoned @liveh2o @mmmries @brianstien