Normalizing casing for property names in JsonException.Path helps deserialization performance #30789
Labels
area-System.Text.Json
design-discussion
Ongoing discussion about design without consensus
tenet-performance
Performance related issue
Milestone
Creating this issue to discuss feasibility of getting this into 5.0. cc @pranavkm @ahsonkhan @rynowak
If we remove support for using the literal JSON value for
JsonException.Path
we can get a ~5% end-to-end performance improvement during deserialization when usingoptions.CaseInsensitivePropertyNames=true
(which is the default for ASP.NET). Allocations are also reduced by ~30% (depends on property name lengths).UPDATE: recent measurements for a very simple case show up to 30% improvement, not 5%. Todo: need to quantify this here.
This means that when case insensitivity is on, the value of the
JsonException.Path
property may not exactly match the property name casing in the JSON (the value is always correct; just the casing can be off).There are three ways the JSON property name is specified:
[JsonPropertyName]
attribute applied to a property.options.PropertyNamingPolicy
such as camel-casing.So currently if there exists JSON like
{"myProp:1"}
against a property namedMyProp
(either through case 1, 2 or 3 above) then when case-insensitivity is on theJsonException.Path
will be"$.myProp"
.However, using the raw JSON value comes at a cost for case insensitivity. Instead if we just use the value obtained from case 1, 2 or 3 (and not the actual JSON) then we get the perf improvement -- e.g. path would be
"$.MyProp"
instead of{"myProp:1"}
(again this would only occur when case insensitivity is on and does not match the actual property name).The text was updated successfully, but these errors were encountered: