Search code examples
.netserializationdatacontractserializer

why DataContractSerializer is faster that xmlSerializer?


Performance wise, why and how Datacontract serializer is better than xmlserializer ?


Solution

  • From: link and also link2

    Is about 10% faster than XmlSerializer to serialize the data because since you don’t have full control over how it is serialize, there is a lot that can be done to optimize the serialization/deserialization process.

    The main differences I have noticed:

    • The output is not formatted
    • The created object does always have it's constructor called, which implies that only one object is created and then the memory is copied for all subsequent objects
    • I suspect there are also other improvements relating to the way it casts the types when deserializing the data.