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

Optimized away the creation of empty string objects. #6502

Merged
merged 1 commit into from Aug 14, 2019

Conversation

haberman
Copy link
Member

Prior to this CL, creating an empty message object would create
two empty string objects for every declared field. First we
created a unique string object for the field's default. Then
we created yet another string object when we assigned the
default value into the message: we called #encode to ensure
that the string would have the correct encoding and be frozen.

I optimized these unnecessary objects away with two fixes:

  1. Memoize the empty string so that we don't create a new empty
    string for every field's default.
  2. If we are assigning a string to a message object, avoid creating
    a new string if the assigned string has the correct encoding and
    is already frozen.

Prior to this CL, creating an empty message object would create
two empty string objects for every declared field.  First we
created a unique string object for the field's default.  Then
we created yet another string object when we assigned the
default value into the message: we called #encode to ensure
that the string would have the correct encoding and be frozen.

I optimized these unnecessary objects away with two fixes:

1. Memoize the empty string so that we don't create a new empty
   string for every field's default.
2. If we are assigning a string to a message object, avoid creating
   a new string if the assigned string has the correct encoding and
   is already frozen.
@haberman
Copy link
Member Author

This PR fixes #6496.

@haberman haberman merged commit 402c28a into protocolbuffers:master Aug 14, 2019
@haberman haberman deleted the rubygcfix branch August 15, 2019 12:03
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