I'm using libxml2′s DOM parser in my iPhone app to parse a XML file with a hundred thousand lines.
I store the content retrieved into a SQLite database. However, this process takes several minutes to complete, <em>too much to be user friendly</em>. My feeling is the biggest part of the time gets lost writing the data into the database.
I'm looking now for any hints on how to make this process more efficient.Answer1:
Try profiling your code with Instruments! Check for the parts of your own code that are taking the most time! See if you can take a different approach (or post the slow code for suggestions)! If possible, use <a href="http://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationObjects/OperationObjects.html%23//apple_ref/doc/uid/TP40008091-CH101-SW1" rel="nofollow">NSOperation / NSOperationQueue</a> to provide progress feedback to the user!
You might also have a look at this question: <a href="https://stackoverflow.com/questions/1711631" rel="nofollow">"How do I improve the performance of SQLite?"</a>Answer3:
Definitely agree with JNozzi. Profile your code first to see where the largest performance bottlenecks are. It's not clear whether it's the XML DOM tree parsing, the XML DOM tree traversal, or the SQLite insertions which are causing the biggest problem.
If DOM tree parsing (or even traversal) is the issue, you should seriously consider switching to one of libxml2's more efficient XML parsing tools: xmlTextReader (the XML pull api) or SAX (the XML push api). I recommend xmlTextReader:
<a href="http://xmlsoft.org/xmlreader.html" rel="nofollow">http://xmlsoft.org/xmlreader.html</a>