Skip to content
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

Ruby lazy wrappers optimization #6797

Merged
merged 8 commits into from Nov 7, 2019

Conversation

haberman
Copy link
Member

@haberman haberman commented Oct 24, 2019

This optimization avoids creating Ruby objects for wrapper types until they are accessed. Ruby has significant per-object overheads, both at allocation and GC time. In messages with lots of wrapper fields, this optimization speeds up parsing greatly.

At parse time, we store wrappers as primitive values in the message. If the field is never accessed, or is only accessed as foo.bar_as_value, we never need to allocate a true Ruby object. Only if a user accesses foo.bar directly do we lazily create the Ruby object.

A few things that don't work or aren't tested yet:
- wrappers at the top level
- equality checking for not-yet-expanded wrappers.
… addressed.

The only case that doesn't work is decoding a wrapper type from JSON
at the top level.  This doesn't make sense and probably no users do it
I changed it to throw.
Copy link
Contributor

@gerben-s gerben-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

Copy link
Contributor

@gerben-s gerben-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked from a brief overview.
Approve for now

@haberman haberman merged commit 0eb9b27 into protocolbuffers:master Nov 7, 2019
@haberman haberman deleted the ruby-lazy-wrappers branch December 6, 2020 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants