An ODataPrimitiveValue wrapper is created for each primitive value that's serialized. When analyzing CPU profiler report from serializing OData resources, the ODataPrimitiveValue constructor appears to be expensive.

My assumption is that the majority of the cost comes from verifying whether a value is a primitive type:

The IsPrimitiveType method looks up the type in a PrimitiveTypeReferenceMap dictionary. Maybe it would be more efficient to compare types directly in an if block instead of relying on dictionary lookups:

Assemblies affected
Microsoft.OData.Core 7.x
Reproduce steps
Run the BenchmarkServer project through a CPU profiler and analyze the metrics.
An
ODataPrimitiveValuewrapper is created for each primitive value that's serialized. When analyzing CPU profiler report from serializing OData resources, theODataPrimitiveValueconstructor appears to be expensive.My assumption is that the majority of the cost comes from verifying whether a value is a primitive type:
The IsPrimitiveType method looks up the type in a
PrimitiveTypeReferenceMapdictionary. Maybe it would be more efficient to compare types directly in anifblock instead of relying on dictionary lookups:Assemblies affected
Microsoft.OData.Core7.xReproduce steps
Run the
BenchmarkServerproject through a CPU profiler and analyze the metrics.