Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linq to xml performance

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?

like image 896
Cyan Avatar asked Feb 06 '11 03:02

Cyan


2 Answers

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.

like image 77
SLaks Avatar answered Oct 06 '22 00:10

SLaks


Check MSDN:Performance (LINQ to XML) and Performance of LINQ to XML by Eric White - Microsoft

like image 41
naveen Avatar answered Oct 05 '22 22:10

naveen