nethermind icon indicating copy to clipboard operation
nethermind copied to clipboard

Move away from Newtonsoft.Json to more performant implementation

Open LukaszRozmej opened this issue 4 years ago • 7 comments

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:

  1. System.Text.Json (.net one)
  2. SpanJson

First evaluate:

  1. Features
  2. Some simple benchmarks of our use cases
  3. Serializers generation: https://www.stevejgordon.co.uk/playing-with-system-text-json-source-generators

Then move:

  1. JsonSerializer
  2. JSON RPC
  3. All the custom converters

LukaszRozmej avatar Nov 11 '21 15:11 LukaszRozmej

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.

640774n6 avatar Nov 18 '21 00:11 640774n6

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

LukaszRozmej avatar Nov 18 '21 01:11 LukaszRozmej

@640774n6 are you planning to work on this? Otherwise someone from internal team might pick it up.

LukaszRozmej avatar Nov 23 '21 15:11 LukaszRozmej

You can reassign it. It's looking like I'm going to be busy this week.

640774n6 avatar Nov 23 '21 17:11 640774n6

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

LukaszRozmej avatar Apr 11 '22 09:04 LukaszRozmej

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.

smartprogrammer93 avatar Aug 12 '22 00:08 smartprogrammer93

@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.

smartprogrammer93 avatar Aug 12 '22 03:08 smartprogrammer93