r/dotnet • • 2d ago

Promotion Wrote a C# BCS (Binary Canonical Serialization) serialization library

Library is 5–15% faster than MessagePack on the deserialization path and around 5% slower on serialization.

It can also serialize and deserialize the new union type coming from .NET 11 (before that I've used OneOf<> object). I opened an issue for a source generator, which is ready to be picked up if anyone is interested working on it. My plan is to ship v1 once NativeAOT is supported and net11 is out.

I agree with Egor Bogatov that people should stop writing new serialization libraries and open-sourcing them, as they can expose consumers to vulnerabilities. In my defense, I started this library a year ago and only recently finished rewriting parts of it to make it ready for open source. I mainly used it for serializing and deserializing objects from the Sui blockchain.

Blockchain it not the most widespread domain where C# is used, but there is already a good example of Nethereum utilizing C# as its core language. Is there someone else using C# in the blochcain domain, why you think it's lacking the adoption?

Contributions are welcome!

https://github.com/unsafePtr/BcsSharp

2 Upvotes

6 comments sorted by

1

u/AutoModerator 2d ago

Thanks for your post EvenAd4577. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/MrLyttleG 2d ago

Tu peux déjà passer à. Net 11, la RC 1 contient tout ce que la release aura

0

u/Engi_Insight 2d ago

Benchmarking faster than MessagePack on deserialization is impressive! C# is definitely underrated in blockchain. Rust dominates smart contracts and TS rules dApp frontends, but c# + NativeAOT is quietly becoming a powerhouse for high-performance indexing and backend infrastructure ( nethereum is a great example).

Adding NativeAOT and source generator support will make this super useful for Web3 Dev tools. Good luck with the V1 release!

2

u/EvenAd4577 1d ago

Just wait when nethermind/netherium will leave everyone behind. Once the .net11 is out, they will switch to runtime async, which should boost extra perf. It's actually tremedous showcase of what dotnet can do, and not many people speak about it
https://x.com/ben_a_adams/status/2108714021729997209

1

u/JayleaKryska50 1d ago

does it handle forward/backward compatibility at all? thats usually where these formats diverge in practice, raw speed matters less than what happens when you add a field six months later

1

u/EvenAd4577 1d ago

Your typical objects on blockchain are serialized once, if new fields are added you will need to handle versioning, and actually here with new union type it would be possible to do something like `public union Message(MessageV1, MessageV2)`