Conversation
Co-authored-by: krishkat <krishna.kater@gmail.com>
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.
In this round, we finished building out the Source Generator and implemented all remaining features.
While the code polishing and final review are not complete yet, we consider the implementation of all planned features to be done.
First of all: v4 achieves extremely fast serialization/deserialization speed even in map mode!
It is even faster than other libraries' array mode.
Serialize
Deserialize
You may notice that v3's performance looks quite bad here. For the sake of benchmark fairness, we use Jil's Stackoverflow Answer as the large POCO, and all of its primitive fields are nullable. v3's Source Generator handles nullables poorly, which causes this performance degradation. Since this is not a particularly common scenario, we may switch to a benchmark with the nullables removed.
As for Nerdbank.MessagePack, it has been updated to the latest v1.3.85, which is why its array performance has improved significantly.
New Features
We added support for the new .NET 11 types and C# 15 unions.
We also support the non-boxing access pattern, so when the case types are structs, this finally delivers the long-requested unions over value types.
Note that as a breaking change to the annotations,
MessagePack.UnionAttributeis renamed toMessagePack.UnionTag. The reason is that it collides withSystem.Runtime.CompilerServices.UnionAttribute, which makes it awkward to use.We intend to take the utmost care with annotation compatibility, but there is one more break: the
TypeofMessagePackFormatterAttributeis now a factoryType instead of a formatterType, which is not compatible. Due to the architectural change, formatters can no longer be instantiated directly, so this change is unavoidable.In addition, the generator-related attributes (
MessagePackAssumedFormattableAttribute,MessagePackKnownFormatterAttribute) are retired. In their place,MessagePackSerializableAttributeandMessagePackKnownTypeAttributeare introduced.By passing a
KeyNamingPolicyat declaration time, you can now apply name conversion in the automatic map mode.We also added the options
ValidateRequiredMembersandValidateNullableAnnotations, which validaterequiredandnullablerespectively. The defaults are true forrequiredand false fornullable. Because of the nature of the language, nullable validation can never be 100% complete, so we judged that opting in deliberately, with an understanding of its limitations, is the better default.Circular references and dedup are now supported. Wrapping every formatter has real problems (versioning resilience, efficiency, and the implementation bleeding into every formatter), so we chose a per-type opt-in approach for the types you want to support. I believe this is a well-balanced approach that poses no problems in practice.
As the equivalent of protobuf's Unknown Fields, we introduce
MessagePackUnknownMembers.We added
IMessagePackSurrogate<TTarget, TSurrogate>, which makes external types without annotations serializable without writing a custom formatter. Once defined, the Source Generator automatically adds it to the standard runtime factory as well, so it automatically becomes serializable in AOT environments too. Note that since it uses static abstract members, it targets modern .NET only.