-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Improve performance of async deserialization #130
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
AArnott
commented
Nov 29, 2024
test/Nerdbank.MessagePack.Tests/MessagePackStreamingReaderTests.cs
Outdated
Show resolved
Hide resolved
I'm sure there are still bugs. And we desparately need analyzers to keep code straight.
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.
The problem with async deserialization perf is that async methods cannot pass
ref struct
around. Passing aroundReadOnlySequence<byte>
to every single read method kills perf.In this change, I radically restructure
MessagePackReader
to createMessagePackStreamingReader
which is aref struct
with all synchronous methods except for one that asynchronously fetches more bytes from an arbitrary source. Doing so destroys theref struct
so the caller has to recreate it. I've done what I can to minimize the syntax overhead on the caller, but it's likely to never be as convenient as theMessagePackReader
. But it's more convenient and complete than the old async model.If we use the
MessagePackStreamingReader
instead ofMessagePackReader
in synchronous converters, the perf is almost as good, but not quite (at least not yet).My dream would be that a converter can be written using the new async pattern and have perf that is competitive with the old sync pattern such that implementing a sync converter and an async converter is no longer necessary in any case.
Other benefits of the new model:
Before
After