MicrosoftDocs / OData-docs

Creative Commons Attribution 4.0 International
33 stars 110 forks source link

OData Client performance guideline to add custom model loader when not using auto-generated code #318

Open habbes opened 3 months ago

habbes commented 3 months ago

When customers create a client using DataServiceContext (without using ODataConnectedService or OData CLI), they usually experience high latencies and CPU usage hikes. This is because, by default, OData Client will fetch the $metadata endpoint and parse the csdl to get the IEdmModel on each request. The solution to this problem is to provide a customer IEdmModel loader delegate. This delegate will be called by OData Client on each request, overriding the default behaviour. To make this call efficient, the customer loader should cache the model to avoid parsing or building the model on each request. This guideline is actually already documented in our guides, but the performance impact is not emphasized, and it's a detail that's easy to miss.

I suggest we add a new section to the performance guidelines documentation that talks about this problem and the solution.

Sample customer issue: https://github.com/OData/odata.net/issues/3015