Josh posted on May 4, 2008 21:11

File this under stuff I should have known...

If you only need read-only access to an XML file, using the XmlReader is much, Much, MUCH faster than loading the file into an XmlDocument object and performing XPath selects.

I have recently been working on a project where I was doing some off-brand serialization/deserialization of objects.  Initially I was simply loading the file into an XmlDocument and doing my node selects.  I had roughly 80 megabytes in 100 XML files and the performance wasn't where I wanted to be.

After doing a bit of research I found that, Duh! the XmlDocument is slow.  I adjusted my code to use an XmlReader for reading the XML files and XmlWriter for saving out the serialized XML.

The results went from 1 minutes, 8 seconds to load using XmlDocument to 8 seconds using XmlReader.

...I should have known this...


Posted in: Coding  Tags: , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009 Josh C.