Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit bb286ac

Browse files
author
Dan McGee
committed
Don't bother title-casing property names for lenient lookup
Profiling shows a significant amount of decoding time (>25%!) in this hotspot when dealing with large, repetitive JSON documents using underscore_style property names and requiring the lenient lookup. The good news is there is no need to title case at all, once we remove hyphens and underscores. The type accessor map uses a case-insensitive lookup function, so any case will do. Note that no tests need modification post-patch (although several would fail without the hyphen/underscore removal).
1 parent 452c1f9 commit bb286ac

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/ServiceStack.Text/Common/DeserializeTypeRefJson.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ public override TypeAccessor GetTypeAccessorForProperty(string propertyName, Dic
2929
{
3030
TypeAccessor typeAccessor;
3131

32-
// camelCase is already supported by default, so no need to add another transform in the tree
33-
return typeAccessorMap.TryGetValue(TransformFromLowercaseUnderscore(propertyName), out typeAccessor)
32+
// map is case-insensitive by default, so simply remove hyphens and underscores
33+
return typeAccessorMap.TryGetValue(RemoveSeparators(propertyName), out typeAccessor)
3434
? typeAccessor
3535
: base.GetTypeAccessorForProperty(propertyName, typeAccessorMap);
3636
}
3737

38-
private static string TransformFromLowercaseUnderscore(string propertyName)
38+
private static string RemoveSeparators(string propertyName)
3939
{
40-
// "lowercase-hyphen" -> "lowercase_underscore" -> LowercaseUnderscore
41-
return propertyName.Replace("-","_").ToTitleCase();
40+
// "lowercase-hyphen" or "lowercase_underscore" -> lowercaseunderscore
41+
return propertyName.Replace("-", String.Empty).Replace("_", String.Empty);
4242
}
4343

4444
}

0 commit comments

Comments
 (0)