Collect converters into one via Dictionary
applejag opened this issue · 1 comments
Description
The converters are many. And because we know that they are locked on the type and does not do any fancy calculations inside the CanConvert method, we might as well toss them into a Dictionary<Type, JsonConverter>
instead of having Newtonsoft.Json loop through every single one for every serialization.
It will have to do the lookup twice for every conversion. But two dictionary lookups is probably faster than a single loop-through-every-item. Needs to be benchmarked!
Motivation
Would make serialization/deserialization faster
Suggested solution
Create a JsonConverter that in its CanConvert does a .ContainsKey
on the dictionary of converters, and inside the ReadJson and WriteJson it just forwards the calls to the appropriate converter.
This is potentionally a breaking change. Moving this to 2.0.0 milestone