FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

MessagePack for C# v4: Round6 by neuecc · Pull Request #2293 · MessagePack-CSharp/MessagePack-CSharp · GitHub

MessagePack for C# v4: Round6 - #2293

Draft
neuecc wants to merge 7 commits into
masterfrom
v4
Draft

MessagePack for C# v4: Round6#2293
neuecc wants to merge 7 commits into
masterfrom
v4

Conversation

neuecc commented Aug 20, 2026
edited
Loading

Copy link
Copy Markdown
Member

This round clarifies v4's feature set.
Contractless, Typeless, DynamicObject, NonGenerics, and Json have been implemented.
In other words, v4 now delivers 100% of v3's functionality, compatible both in features and in input/output binary.
The target frameworks are identical as well (netstandard2.0 floor), so there is no barrier for v3 users to upgrade.

Honestly, these features were well isolated — the design consistently kept options from bleeding into the body of other formatters — so none of these features, present since v1, ever amounted to technical debt.
They also separate cleanly between the NativeAOT and JIT paths, so they pose no obstacle to NativeAOT support either.
That said, as a safety consideration, the blacklist-style Typeless is marked as Obsolete.

As for Contractless/DynamicObject, v3 emitted the entire formatter body with IL.Emit; v4 switches to per-property delegation.
This is a maintenance-cost decision: whole-body Emit makes the IL implementation and its upkeep far too expensive.
The Source Generator path is what normally runs, and these are positioned as fallbacks, so by deliberately not chasing extreme performance, we balance functionality against maintenance cost.

Performance compared with v3 and other libraries:

The Stack Overflow API Answer graph (Answer → ShallowUser → BadgeCount, Answer → List<Comment> → ShallowUser, byte enums, DateTimes, ~1.65KB payload), [Key(int)] array format.
i7-13700KF, .NET 10.0.5, BenchmarkDotNet MediumRun (2 launches × 15 iterations).

Method Impl Mean Ratio
Serialize v4 (Source Generator) 381.3 ns 1.00
Serialize v4 (DynamicObject) 734.9 ns 1.93
Serialize v3 (Source Generator) 784.9 ns 2.06
Serialize v3 (DynamicObjectResolver) 1,108.3 ns 2.91
Serialize Nerdbank.MessagePack (PolyType shape) 1,175.9 ns 3.08
Deserialize v4 (Source Generator) 833.3 ns 1.00
Deserialize v4 (DynamicObject) 1,069.1 ns 1.28
Deserialize v3 (Source Generator) 1,357.5 ns 1.63
Deserialize v3 (DynamicObjectResolver) 1,529.9 ns 1.84
Deserialize Nerdbank.MessagePack (PolyType shape) 1,853.6 ns 2.23

v4 DynamicObject is by no means the best possible performance, yet it still outperforms v3.
This is because the underlying baseline is fast enough to leave headroom in the performance budget.
If v4's baseline had been merely on par with v3, the fallback would have meant an actual regression — fallback or not, that would have been hard to accept.
This is one more place where the pursuit of raw performance pays off.
With the guarantee that "it never gets worse than v3" in hand, I'm proceeding with this implementation approach.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL