2

I used .NET DataContractSerializer for deserializing an object tree from a file, within 3 seconds the first time the application was loaded. When I run the same deserialization step again and again it only takes 1.5 s.

What is the reason for that? And are there any chances to improve performance for the first time deserialization (like bringing it down to 1.5 s too)?

Martin Komischke
  • 1,440
  • 1
  • 13
  • 24

1 Answers1

3

Have you tried using SGen? The first time the process tries to deserialze, it has to generate the serialization code using reflection. This adds considerable cost to the first run.

When the XML Serializer Generator is not used, a XmlSerializer generates serialization code and a serialization assembly for each type every time an application is run. To improve the performance of XML serialization startup, use the Sgen.exe tool to generate those assemblies the assemblies in advance. These assemblies can then be deployed with the application.

Rob
  • 4,327
  • 6
  • 29
  • 55