Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
329 stars 45 forks source link

Very poor performance when using `JsonUnionEncoding.ThothLike` and DU * DU map #96

Closed peterhirn closed 3 years ago

peterhirn commented 3 years ago

Hello,

I'm trying to serialize a record which contains a field Map<DU, DU>. I understand that this is probably a strange edge-case.

I previously implemented the serializer using Thoth.Json.Net (which uses Newtonsoft) and came to the conclusion, that there must be a performance problem with that project, since serializing a 1mb file took 6 seconds, but when using Newtonsoft directly it only took around 500ms (with the default DU serialization).

So I re-implemented the serializer using this project, since you support the 'TothLike' union style. As it turns out, the runtime is almost identical to Thoth.Json.Net when using JsonUnionEncoding.ThothLike vs. the default settings (~6 seconds vs. ~500ms).

10x runtime, how is that possible? Am I doing it wrong?

Edit: Sorry, I really should have tested this better before opening this issue. Serialization is very fast, didn't measure the right thing.