-
Notifications
You must be signed in to change notification settings - Fork 0
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
Remove placeholders #2
Merged
Merged
Conversation
This file contains 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.
Summary
Hello!
This is a first step in removing the
PLACEHOLDER
mechanism to greatly improve performance, make the whole code more Pythonic and simple and resolve a lot of bug. The motivation is more deeply described in danielgtaylor/python-betterproto#631This PR completely removes placeholder values from messages. Instead, fields are always set with there default value (empty string, 0,
None
for optional, members of a oneof and messages, ...). Therefore, all the message field are marked as optional and can be set to None, which is coherent with the specification (see the issue).As a consequence, this fixes the following issues:
Before merging it, I think it would be good to finish the work in progress (at least my other PR and another fix of the generation of the comments), and release a new version with all the recent bugfixes.
Performance
These changes also make it possible to remove the
__getattribute__
from messages. As expected, this has a great impact on the performance.With the following messages:
The following code takes 3.24s on my computer with the original (
master
) implementation with the Rust codec, and only 2s with my PR (without the Rust codec). Thus, even if the Rust codec is not supported for now, it is not a problem since the performance are better anyway.Breaking changes
This PR introduces two small breaking changes:
None
as value andgetattribute
is no longer defined.serialized_on_wire
function is now removed, since messages that were not serialized on the wire are now represented asNone
values. This function didn't really make sense in the first place imo, since being serialized is a property of a field of a message, not a property of a message itself (google's version hasHasField
, which indeed takes the field as a parameter).Checklist