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

Parse serialization headers only once #2784

Merged
merged 3 commits into from
Jul 3, 2023
Merged

Conversation

benclifford
Copy link
Collaborator

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

  • Code maintentance/cleanup

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 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...
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
Copy link
Collaborator

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

@benclifford benclifford merged commit 9b5c832 into master Jul 3, 2023
@benclifford benclifford deleted the benc-serialization-headers branch July 3, 2023 21:19
benclifford added a commit that referenced this pull request Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants