MscrmTools / MscrmTools.Xrm.Connection

Provides Winforms control to connect to Microsoft Dynamics CRM deployments
GNU Lesser General Public License v3.0
23 stars 38 forks source link

Metadata cache - convert to JSON for better performance #148

Closed MarkMpn closed 3 years ago

MarkMpn commented 3 years ago

This changes the metadata cache to using Json.NET for the serializer instead of the previous DataContractSerializer. Although D365 appears to use DataContractSerializer a lot internally, Json.NET takes 1-2 seconds less to deserialize the metadata - this gives a better user experience when connecting to an instance for the first time. In my tests this brings the time down to around 2 seconds for a PowerApps environment and 4 seconds for a D365 Sales environment.

To try to improve performance further, this will also trigger Json.NET to generate its internal contracts that it uses for serialization/deserialization in the static constructor, so they should be ready by the time the user starts the first connection - this saves another 0.5 seconds or so.

Where possible (if the connection is using OData authentication) this also uses a clone of the service client to get the updated metadata to avoid the locking inside the service client if the tool is trying to use the connection at the same time.

If a change to the metadata is detected, the updated cache file is generated in the background so the user can still be working while this is being written.