This protobuf-net page shows the performance of DataContractSerializer
to be significantly better than XmlSerializer
. Of course, you should always test with your own data, but if you are looking to replace XmlSerializer
, you will most likely find DataContractSerializer
to be a performance improvement.
I'm not sure how DataContractSerializer
is implemented internally, but generally serializers are highly optimized. This is especially true for DataContractSerializer
since it is a big part of the performance picture for WCF. It is not uncommon for a serializer to generate MSIL code on the fly. When this is done, DynamicMethod
allows you to (surprisingly!) bypass visibility checks (see MSDN), so it is possible to access private fields without reflection.
From MSDN:
Given sufficient security permissions,
a serialization engine implemented
using dynamic methods can access
private and protected data to enable
serialization of objects not authored
by the engine creator.