Open Thorium opened 8 months ago
The figures are still so bad that people should prefer System.Text.Json and Newtonsoft.Json over this library.
Yes, far too many moving parts If going NSJ (which is a bad idea for new systems as it's a dead end), FsCodec.NewtonsoftJson includes required converters for things like options (FsCodec.SystemTextJson has shims too, but those are a lot less necessary than they are for NSJ) Also if you want lots of features and dot mind taking a dep on a larger lib, look at FSharp.SystemTextJson
I asked @eiriktsarpalis the best method for custom parsing json with System.Text.Json, he said:
just use Utf8JsonReader under wraps. That way make sure it's compliant and also take advantage of all the vectorization code it's using under the hood.
So I tried a bit: https://gist.github.com/Thorium/09a67ce08adee4fcc02ec7f0048e6962 That could work here as well.
I should mention though - while GC and perf for STJ is in another league, ultimately the perf of JSON serialization is not make or break for 99% of systems. i.e. my motivations for mentioning other libs is not primarily based on perf, more:
Fair point, however often JSON is used in data communications which often means there is either active user looking progress-bar, or there is a huge batch process going on, so speed is somewhat a property.
Beside the options you mentioned there is FSharp.Data.JsonProvider which is extremely convenient to use, having its own parser.
Right now I feel that F# eco-system has had this problem of everyone copy&pasting their own serialization implementations (and AI-tools will make this even easier in the future). And because everything is OSS, people also referencing single serialization-implementation files directly (e.g. paket files). That's why fixing old code is important even in old less-maintained sources.
This commit reduces the memory usage and speeds up all the serialization.
I used also the benchmark-branch all the test that did have result for FSharp.Json, to run test between the current version and this commit, both run with latest FSharp.Core. Here are the results: