Move away from Newtonsoft.Json to more performant implementation
https://medium.com/justeattakeaway-tech/json-serialization-libraries-performance-tests-b54cbb3cccbb
Please note this evaluation may be somewhat obsolete in .net6 (mainly System.Text.Json improvements)
Probably best candidates:
- System.Text.Json (.net one)
- SpanJson
First evaluate:
- Features
- Some simple benchmarks of our use cases
- Serializers generation: https://www.stevejgordon.co.uk/playing-with-system-text-json-source-generators
Then move:
- JsonSerializer
- JSON RPC
- All the custom converters
Doesn't appear that SpanJson has had much maintenance lately either. (last commit a 1 yr ago).
I'll try and setup a realistic benchmark. My gut says best maintenance to performance ratio will be System.Text.Json (Since the plan is to target net6.0), but still worth the exercise of benchmarking the specific use-cases here to create an educated discussion.
The worst case scenario, would be some big response to eth_getLogs which is written to a stream and chunked, or some big debug_trace or trace_call. But we should test both big and smaller ones.
Please note .net6 migration is not yet merged: https://github.com/NethermindEth/nethermind/pull/3554
@640774n6 are you planning to work on this? Otherwise someone from internal team might pick it up.
You can reassign it. It's looking like I'm going to be busy this week.
If System.Text.Json is used, this will be helpful: https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to?pivots=dotnet-6-0
So i tried to work on this a little bit. i think the biggest problem that we might have are the converters. otherwise i believe it can go smoothly. Already converted one convertor to System.Text.Json with no problems. It will take some time though.
@LukaszRozmej you can check out ABIParsing using System.Text.Json in the referenced PR. Please note this implementation does not use source generation to optimize performance. Performance with source gen. would be way better.