Utf8Json or Jil for Net3.5
Hey there! I'm trying to improve the performance of a game made in an older version of Unity that uses Net 3.5, and want to find a better JSON serializer and deserializer (current is JsonFx). I read about Utf8Json and Jil, but there don't seem to be any 3.5 versions available, even though I have read several articles and StackOverflow posts that mention them. Any help is much appreciated!
12 Replies
.NET 3.5 is ancient. Like, 4.0 came out 14 years ago
So no, noone bothers to support it any more. You're very unlikely to find modern(ish) packages with .NET 3.5 support
Is json serialization/deserialization really a bottleneck in your game? Are you really serializing and deserializing json all the time?
It's the bottleneck for load times, definitely. It's not my game, and the devs are not good at what they do.
My point is, there is talk about using Utf8 or Jil in Net3, 3.1 and 3.5 online, but no downloadable version to use.
Utf8Json looks like it has a Unity-3.5 version here:
https://github.com/neuecc/Utf8Json/tree/master/src/Utf8Json.UnityClient
Per https://github.com/kevin-montrose/Jil/issues/192, looks like there's no support for Jil on .NET Framework 3.5.
Note: Utf8Json is no longer actively maintained.
Thanks!! Will check it out!
Active support is not needed. The game (Sunless Sea) has had a single bugfix since 2018, so as long as it works now, it'll work forever.
Okay, so I'm having trouble trying to build the project.
Is there some context I am missing when trying to build?
[Info : Console] Error occurred while processing JSON for 'exchanges': Could not load type 'Swifter.Json.JsonFormatter' from assembly 'Swifter.Json, Version=1.6.0.9, Culture=neutral, PublicKeyToken=4803cb8548668d48'.
New error:
[Info : Console] Error occurred while processing JSON for 'exchanges': Could not load type 'Swifter.Tools.HGlobalCache`1' from assembly 'Swifter.Core, Version=1.6.0.9, Culture=neutral, PublicKeyToken=5c52005388a7b388'.
Swifter.Json is its own nuget library. I don't know why your project would be referencing it directly.
(I also know nothing about Swifter and can't make any recommendations regarding it. Sorry.)
Understandable. Here is the relevant csproj lines:
<PackageReference Include="Swifter.Core" Version="1.6.0.9" />
<PackageReference Include="Swifter.Json" Version="1.6.0.9" />
It's not loading it directly.
I am using the examples provided on the github, but I'm not sure how this error can even happen. Intellisense doesn't pick up on the error, only when running.
These are issues I've NEVER had to deal with.
Swifter.Json is its own nuget library. I don't know why your project would be referencing it directly.If you meant by this that I should not be using Swifter because I was using Utf8, I stopped using that, because what I'm after is just a dll I can use. All avenues Utf8 lead me down required me to build the project, or just led me to a .unitypackage file, which I can't use, since I don't have a project file. I even installed Unity 2018 to try to build the project which might net me a dll, but there were hundreds of unexplained errors, such as one I sent above. https://discord.com/channels/143867839282020352/1295810970572292231/1295852544802947083 In the end, I just need a dll for a faster JSON deserializer (that works). I have no clue why it wouldn't work and the error message is no help at all.
For 3.5, the popular JSON deserializers are Newtonsoft.Json (OSS) or DataContractJsonSerializer (ships as part of .NET Framework 3.5)
But even the slowest deserializers are still pretty fast overall. I'm really surprised to hear these would be bottlenecking you unless you're deserializing hundreds of MB as part of a level load.
Each deserialize operation has overhead. Deserializing a million small payloads is going to be much, much slower than deserializing a single large payload.
If that's the case, and assuming all the small payloads are the same type of object, concat them together into a single large payload and deserialize the single large payload.
So { foo } and { bar } and { baz } become "[ { foo }, { bar }, { baz }]" and you deserialize it as an array.
Nope. A single payload is being deserialized into a List<T>
The developers over at Failbetter games are not known for being good at coding. JsonFx is quite slow, but that only compounds the effect of their lack of optimisation. They've been using the same system for ages... And the tech debt is really weighing the system down. Deserializing into List<Failbetter.Core.Event>> takes 8 seconds, List<Dictionary<string,object>> takes 2.
The code is pretty locked down. Only way I can hope to improve performance is to use a different deserializer.
I would look into Newtonsoft.Json then if you're looking for something that works relatively well on 3.5 and you're not married to Jil or utf8json
But keep in mind that not all deserializers are interchangeable. If jsonfx has some bespoke behavior that other deserializers don't have, well, you might not be able to yank it out.
True. I think I can iron out the kinks when I get it running though. Problem is that I haven't gotten this stuff to run a single time. Although it might not look like it from this thread, I'm pretty decent at coding, and when I encounter a problem, I'm persistent in solving it. The problem here is that this is a problem that I've never heard of and doesn't really make sense, and seemingly nobody else has had this problem either.
[Info : Console] Error occurred while processing JSON for 'events': Could not load file or assembly 'System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.With Newtonsoft :) Something seems to be very wrong. This is a new one: