Code Monkey home page Code Monkey logo

Comments (2)

kiminuo avatar kiminuo commented on July 21, 2024 1

👉Handling null values

* Newtonsoft reads the null as value, and we can edit the converter's read function as we would like to handle null.

* Microsoft instead recognizes the null value, and returns it immediately, without even calling the converters read function.[1](#user-content-fn-1%5E-64dc658316f281646fb204ab00f6232c)

This is wrong, there is a setting for it on STJ's side and I fixed it in your PR. It's documented here and it contains a nice explanation as well:

This null-handling behavior is primarily to optimize performance by skipping an extra call to the converter. In addition, it avoids forcing converters for nullable types to check for null at the start of every Read and Write method override.

To enable a custom converter to handle null for a reference or value type, override JsonConverter.HandleNull to return true, as shown in the following example:

🟡 Would replacing all of those with Microsoft Json converters would increase the performance?

Yes, it would decrease the running time and memory usage.

🟡 By a lot?

Not really.

In my mind, this is not really an argument. It depends on use cases. For startup, it gives a non-trivial speedup improvement because Adam wants to load the software in at most 400 ms.

For Backend, the argument should be "how many JSON serialization/deserializations happen" and how much CPU time/memory would be saved.

Is it worth it to burn days and weeks for some (hopefully, at least) seconds of improvements in serializing and deserializing jsons?

You tell me. IMHO, it's not really.

It is worth optimizing where it makes sense. #11840 allows precisely that. It does not force to take any specific action right now. It gives more options and that was the point.

Btw:

  • Newtonsoft.JSON is not being actively developed and there is a lot of resources pouring into STJ.
  • With STJ, the bet on NativeAOT, app trimming (to decrease app's size) is much better than with Newtonsoft.JSON.
  • If we get rid of Newtonsoft, we would have one less dependency, which is not bad either.
  • STJ likely will get faster with every release, not true for Newtonsoft.

from walletwasabi.

molnard avatar molnard commented on July 21, 2024

Useful information thx for the record. Closing it to aggregate the problem into one issue. #4223

from walletwasabi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.