-
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
Speed Up Creates & Updates By Memoizing on encode #293
Speed Up Creates & Updates By Memoizing on encode #293
Conversation
@@ -27,6 +27,11 @@ class Message | |||
include ::Protobuf::Message::Serialization | |||
|
|||
## | |||
# Attributes | |||
# | |||
attr_accessor :memoized_encoded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would we need the attr_accessor? (either of them)
@@ -195,6 +195,7 @@ def define_array_setter | |||
|
|||
message_class.class_eval do | |||
define_method(method_name) do |val| | |||
@memoized_encoded = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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