I heard that LINQ to XML has some performance issues and some of my friends recommended me not to use it in my app. I couldn't find anything relevant on MSDN and I do not want to rely on "some internet blog". Does anyone know of a official point of view on this issue or some trustworthy source?
Using LINQ to XML will read the entire file into memory.
If you're reading an enormous XML file (hundreds of megabytes), this is a problem.
Instead, you can use a raw XmlReader, which provides a forward-only view of an XML file and will not read the entire file at once.
If you're dealing with normal-sized XML files, LINQ to XML will be fine.
LINQ to XML is several orders of magnitude easier to use than XmlReader.
You should only use XmlReader if you know that you'll be dealing with 200MB XML files, or if you've measured your performance and proved that the XDocument
constructor is being too slow.
Check MSDN:Performance (LINQ to XML) and Performance of LINQ to XML by Eric White - Microsoft
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With