-
Notifications
You must be signed in to change notification settings - Fork 195
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
Parse serialization headers only once #2784
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
Prior to this PR, the serialization header was parsed twice during deserialization, and in two different ways, leading to an awkward header format: the header must be exactly three bytes long for one (length based) parser, and the third byte must be a \n for the other (new-line based) parser. This PR removes the length based parser, instead allowing an arbitrary length \n-terminated header. Backwards/forwards compatibility: The parsl serialization wire format is not a user exposed interface, as parsl requires the same version of parsl to be installed at all locations in a parsl deployment. This PR does not change any on the wire byte sequences when used with the two existing de*serializers, but opens the opportunity for future implementations to use more than two bytes for identifiers. Performance: I made a basic benchmark of serializing and deserializing a few thousand integers (deliberately using a simple object like `int` so that the object processing would be quite small, allowing changes in header time more chance to show up). My main concern with this PR is that I didn't make things noticeably worse, not to improve performance. After this PR, a serialization->deserialization round trip is about 200ns faster (1165ns before vs 965ns after), so I am happy that this PR does not] damage performance. Future: This is part of ongoing work to introduce user pluggable de*serializers.
benclifford
changed the title
Parse serialization header only once
Parse serialization headers only once
Jul 1, 2023
This was only used for determining the constant value 3. As part of a move towards open-world serializer plugins, there will not be a canonical import time list of available serializers, so (computed) constants like this `headers` list probably have to go away to support that...
khk-globus
reviewed
Jul 3, 2023
Comment on lines
76
to
82
else: | ||
for method in methods_for_data.values(): | ||
try: | ||
result = method.serialize(obj) | ||
result = method._identifier + b'\n' + method.serialize(obj) | ||
except Exception as e: | ||
result = e | ||
continue |
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.
As an aside, these two branches are soooo-close. An opportunity to DRY:
serde_methods = methods_for_code if callable(obj) else methods_for_data
for method in serde_methods.values():
try:
result = method._identifier + b'\n' + method.serialize(obj)
break
except Exception as e:
result = e
continue
khk-globus
approved these changes
Jul 3, 2023
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.
Prior to this PR, the serialization header was parsed twice during deserialization, and in two different ways, leading to an awkward header format: the header must be exactly three bytes long for one (length based) parser, and the third byte must be a \n for the other (new-line based) parser.
This PR removes the length based parser, instead allowing an arbitrary length \n-terminated header.
Backwards/forwards compatibility:
The parsl serialization wire format is not a user exposed interface, as parsl requires the same version of parsl to be installed at all locations in a parsl deployment.
This PR does not change any on the wire byte sequences when used with the two existing de*serializers, but opens the opportunity for future implementations to use more than two bytes for identifiers.
Performance:
I made a basic benchmark of serializing and deserializing a few thousand integers (deliberately using a simple object like
int
so that the object processing would be quite small, allowing changes in header time more chance to show up). My main concern with this PR is that I didn't make things noticeably worse, not to improve performance.After this PR, a serialization->deserialization round trip is about 200ns faster (1165ns before vs 965ns after), so I am happy that this PR does not] damage performance.
Future:
This is part of ongoing work to introduce user pluggable de*serializers.
Type of change