AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

Perf: Creating OData properties is expensive

Open habbes opened this issue 2 years ago • 3 comments

During serialization, a relatively high amount of CPU is used to create ODataProperty instances that are used to populate ODataResource objects. This is performed in the ODataSerializerPropertyHelper.CreateProperty method.

The most of the cost come's from the property's EDM serializer's call to CreateODataValue.

image

The ODataPrimitiveSerializer.CreateODataValue:

  • makes expensive calls to ODL's EdmTypeSemantics, see: https://github.com/OData/odata.net/issues/2807
  • ODataPrimitiveSerializer.ConverUnsupportedPrimitives seems to be expensive due to its reliance on Type.GetTypeCode(). We should assess whether there are more efficient ways to handle CLR primitive types that are not part of ODL's core primitive types.

The ODataEnumSerializer.CreateODataValue:

  • retrieves the ClrEnumMemberAnnotation from the the IEdmModel annotations cache. This model's annotation cache is constant performance hog that does not seem easy to optimize.
  • does an expensive dictionary lookup to retrieve the EDM enum value corresponding to the CLR enum value
  • makes an expensive call to Enum.ToString()

habbes avatar Nov 28 '23 14:11 habbes

@habbes what framework version are you targeting on those tests?

julealgon avatar Nov 28 '23 14:11 julealgon

@julealgon the tests were running on net7.0, should try them on net8.0 as well.

habbes avatar Nov 29 '23 04:11 habbes

@julealgon the tests were running on net7.0, should try them on net8.0 as well.

I was going to suggest that considering how many perf enhancements there were in .NET8. Would be curious to compare the results.

julealgon avatar Nov 29 '23 14:11 julealgon