-
Notifications
You must be signed in to change notification settings - Fork 605
Serialization optimizations #801
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
Serialization optimizations #801
Conversation
@stebet thanks again! Just so you know I'm hoping to wrap up version I'm assuming I can run your benchmark application to see the direct benefit of this change? |
You should be able to use the benchmark app yes, but doubt you'll see a big change, unless you can manage quite a bit of throughput. This is mostly the result of me benchmarking the old vs new way of (de)serializing and making some fine-tuning adjustment. No more surprises for the time being :) |
If you take the code from the TestNetworkByteOrderSerialization test and run that in a tight loop with a profiler attached, you should see a hefty change. |
@stebet I was wondering why the change away from BinaryPrimitives? Would you mind explaining it to me? |
BinaryPrimitives were slower on .NET Framework. Will be reintroduced in 7.0 probably. |
if it's only for .NET Framework, would it be an option to compile the .Net standard one with different code? Or will Full Framework users also use the standard one? 🤔 |
It could but BinaryPrimitives on .NET Core aren't really faster (although they are simpler), so I don't see a point in doing in doing code branching based on TFMs or compilation symbols for the 6.x branch. |
At least in my tests (don't have the numbers anymore, have to dig them back up later) with .net core 3.1, the conversion of 10x ulong went from ~50 ns down to 5 ns by using the BinaryPrimitives instead of the manual conversion. (Was the only one I quickly checked) |
Did you use BenchmarkDotNet? |
Yes I did, here are the number for my quick test: BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.836 (1909/November2018Update/19H2) Job=ShortRun IterationCount=3 LaunchCount=1
|
Proposed Changes
Optimizations for (de)serialization of short, ushort, int, uint, long and ulong, basically forcing Network-Order at all times, regardless of architecture. This gets rid of a lot of redundant endianness checks making the code a bit more verbose but performing a lot better. Some code in here had actually regressed quite a bit from the original implementation from a pure serialization perspective, although it was still faster due to overhead in the old NetworkBinaryReader class. This should bring best of both worlds :)
Types of Changes
What types of changes does your code introduce to this project?
Checklist
CONTRIBUTING.md
document