Perf: Creating OData properties is expensive
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.
The ODataPrimitiveSerializer.CreateODataValue:
- makes expensive calls to ODL's
EdmTypeSemantics, see: https://github.com/OData/odata.net/issues/2807 ODataPrimitiveSerializer.ConverUnsupportedPrimitivesseems to be expensive due to its reliance onType.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
ClrEnumMemberAnnotationfrom the theIEdmModelannotations 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 what framework version are you targeting on those tests?
@julealgon the tests were running on net7.0, should try them on net8.0 as well.
@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.