Skip to content

Perf: ODataPrimitiveValue constructor is relatively expensive #2806

@habbes

Description

@habbes

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.

image

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

image

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:

image

Assemblies affected

Microsoft.OData.Core 7.x

Reproduce steps

Run the BenchmarkServer project through a CPU profiler and analyze the metrics.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions