Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes
UnknownFieldsone pointer in size again.#3813 stored all unknown fields in one
Datavalue, which madeUnknownFields16 bytes andExtensibleUnknownFields24 bytes.Every generated message holds one of these, and nested messages are stored inline, so large messages grew a lot.
In debug builds, code that copies large messages could overflow the 512 KB stack of a Swift concurrency thread.
UnknownFieldsnow holds an optional reference to a final class box that owns theData.The reference is nil when there are no fields, so a message without unknown fields does not allocate and
isEmptyis a nil check.Copies share the box.
A mutation reuses the box when
isKnownUniquelyReferencedis true, and makes a new box otherwise.UnknownFieldsis now 8 bytes andExtensibleUnknownFieldsis 16 bytes.The public API does not change.
One buffer, tag order,
fieldsByTag,Equatable,Hashable,Codable, the debug assertion and the encoded bytes behave as in #3813.Decoding a message without unknown fields does not allocate more than before.
Decoding a message with unknown fields allocates one more small object for the box.
The reader still builds the bytes in its own buffer, so appending during decode does not copy the data for each field.
Release note: Swift
UnknownFieldsis now 8 bytes andExtensibleUnknownFieldsis 16 bytes, as they were before 8.0.0-alpha01, so generated Swift messages no longer grow.