Orleans: Switch to System.Text.Json APIs

Created on 27 Oct 2019  Â·  20Comments  Â·  Source: dotnet/orleans

The new System.Text.Json API's provide a slight performance boost over Newtonsoft.Json and I believe the gap will get wider with further releases. This boost is even more prevalant if you serialize directly to and from UTF-8 bytes.

Are there any plans to migrate to this as the new default and possible enable the ability to switch between the two formats like in ASP.NET Core?

Most helpful comment

I do not expect big jumps in performance any more. It is more likely that it will be a little bit slower when more feature are added over time.

When you talk about serializers there are hundreds of places. Each storage provider has its own dependencies and some scenarios like in MongoDB are also not possible with System.Text.Json https://github.com/OrleansContrib/Orleans.Providers.MongoDB/blob/master/Orleans.Providers.MongoDB/StorageProviders/JsonBsonConverter.cs

All 20 comments

I like the idea of improving json performance but I think https://github.com/neuecc/Utf8Json would be better aka faster

Do you have benchmarks for System.Text.Json vs Utf8Json? They follow the same principle.

I think the biggest value of Newtonsoft.Json are the number of serializers. And if you look to the benchmarks in the blog then the performance benefit of System.Text.Json is not that big in real world scenarios.

I think the performance benefit will be greater in time. This API is going to get a lot of eyes on it now. It's also part of dotnet. Ideally the JSON serialiser should be switchable like Asp.net.

I do not expect big jumps in performance any more. It is more likely that it will be a little bit slower when more feature are added over time.

When you talk about serializers there are hundreds of places. Each storage provider has its own dependencies and some scenarios like in MongoDB are also not possible with System.Text.Json https://github.com/OrleansContrib/Orleans.Providers.MongoDB/blob/master/Orleans.Providers.MongoDB/StorageProviders/JsonBsonConverter.cs

A common interface that could be used in all these places would allow you to switch out different serializers easily. ASP.NET Core has done something similar.

System.Text.Json is still not finished and cannot be used (for example) as a drop-in replacement for Newtonsoft. So one need to be a really careful when trying to switch to it. We've tried - and switched back to Newtonsoft on our project because of too much customizations already done that are not supported by this new api.

Sounds like the consensus is that a switch like this would be at least premature. Should we close this until something changes materially?

Is it possible to make the default serializer switchable in readyness for System.Text.Json (There are a bunch of fixes and improvements coming in .NET Core 3.1)? Is that possible or does Orleans use too many of Newtonsoft.Json low level features?

This would be a breaking change. I am very sure that most storage providers would have a problem. There will probably a lot of changes around serialization, e.g. System.Text.Json does not even provide a converter for TimeSpan and inheritance will be a problem as well.

But a good start would be to check the converters: https://github.com/dotnet/orleans/blob/5b1d9cdf41f00cecd0f914667f1ca1a809c50e30/src/Orleans.Core/Serialization/OrleansJsonSerializer.cs

It seems to me that a general change is a non-starter. However, individual providers could take a dependency on System.Text.Json if it makes sense.

Since JSON is not used for messaging, the performance improvements I think are unlikely to become noticeable in the big scheme of things if they only contribute to persitence.

Mmmm... but System.Text.Json is nice :-)

I've just kicked the tires of version 3.0.1, and man! This is really good stuff! I enjoy it so much, and make exhaustive use of the DI with State. Really good stuff! Everything also ties very nicely into generic host, so BIG Kudos to everyone that contributed to Orleans!

Thanks people!

Mmmm... but System.Text.Json is nice :-)

no, it is not :)

Hmm... that is solved by a nice plugin (by design they left out stuff that
newtonsoft has out of the box), as a coincidence I happen to have written
such a nice polymorphic serializer plugin to system.text.json :-) :-)

Den tors 2 jan. 2020 11:39justmara notifications@github.com skrev:

Mmmm... but System.Text.Json is nice :-)

no, it is not https://github.com/dotnet/corefx/issues/38650 :)

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/dotnet/orleans/issues/6070?email_source=notifications&email_token=ACYO3SGPUJUZQNGL4XHW2SLQ3W76DA5CNFSM4JFQVPTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH6CAXA#issuecomment-570171484,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACYO3SCD2RC2DAE6FMUCJLLQ3W76DANCNFSM4JFQVPTA
.

as a coincidence I happen to have written
such a nice polymorphic serializer plugin to system.text.json :-) :-)

Would you be willing to share that? I would be interested in seeing how it was done :)

@ahsonkhan I think this one or something like it is meant, but its... kinda disputable

Nope, as I wrote, I did the plugin myself...

Den tis 7 jan. 2020 10:16justmara notifications@github.com skrev:

@ahsonkhan https://github.com/ahsonkhan I think he means this one
https://github.com/dahomey-technologies/Dahomey.Json, but its... kinda
disputable

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/dotnet/orleans/issues/6070?email_source=notifications&email_token=ACYO3SFSK5UL3PZ4AFD3BXTQ4RB53A5CNFSM4JFQVPTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIIG5VA#issuecomment-571502292,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACYO3SFUO3DFJWS5R2TCTNLQ4RB53ANCNFSM4JFQVPTA
.

I checked it out, and the solution pointed to is kind of involved, a lot of
moving parts. The solution I made is much less involved, but covers all my
needs. In short, I push as much as I can to the system.text.json
serializer, but do some basic (small) housekeeping that's needed. No need
to write a handler for each basic runtime type.

Den tis 7 jan. 2020 12:42Jan Johansson jan.johansson.mr@gmail.com skrev:

Nope, as I wrote, I did the plugin myself...

Den tis 7 jan. 2020 10:16justmara notifications@github.com skrev:

@ahsonkhan https://github.com/ahsonkhan I think he means this one
https://github.com/dahomey-technologies/Dahomey.Json, but its... kinda
disputable

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/dotnet/orleans/issues/6070?email_source=notifications&email_token=ACYO3SFSK5UL3PZ4AFD3BXTQ4RB53A5CNFSM4JFQVPTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIIG5VA#issuecomment-571502292,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACYO3SFUO3DFJWS5R2TCTNLQ4RB53ANCNFSM4JFQVPTA
.

I've done my best to match parity across the different libs, but the above issue really killed that dream.
https://github.com/electricessence/Open.Serialization

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Liversage picture Liversage  Â·  4Comments

gabikliot picture gabikliot  Â·  4Comments

galvesribeiro picture galvesribeiro  Â·  4Comments

DixonDs picture DixonDs  Â·  4Comments

SebastianStehle picture SebastianStehle  Â·  4Comments