javaandroidxmlxml-parsing

How Can I Speed Up Android XML Parsing?


Good afternoon (depending on where you live)!

I'm fairly new to Android development and I'm currently working on moving the functionality from an existing iOS app to Android. Part of this functionality is to parse a "large" (~13,000 line) RSS XML file that contains about 500 entries. I've spent anywhere from 10-15 hours researching XML parsing on Android AND trying out the major XML parsers: DOM, SAX, and Pull-parsing. Here are my results, running within' the emulator on my box (32-bit Windows Vista, 2.2 GHz Dual CPU, 3 GB RAM):

SAX: ~6:00 minutes

Pull-Parsing: ~4:00 minutes

DOM: Greater than 4:00 minutes, but didn't time it when I had that implementation coded.

I also tried this RSS Reader from github, but it took >10:00 minutes:

https://github.com/matshofman/Android-RSS-Reader-Library

The implementations for the SAX, PP, and DOM were all taken from stackoverflow.com threads, so I feel fairly confident that I didn't do anything non-standard in them (though, I'm not ruling that out). I've decided to appeal to a larger, more experienced, crowd to get some ideas of what else I can try.

I don't have any control over the format of the file. If I was implementing this end-to-end, I would just write a Web Service that did all the heavy-lifting on the server and then sent down a small, compact, JSON-serialized list. Instead, I have the 13K line file. :)

Any insight into what I can do? It seems to be a fairly common problem, but most responses just say to try one of the different main XML parsers. In my case, I've tried all three and even the fastest seems way too slow.

What am I doing wrong? Are there any normal "newbie" problems that people usually encounter when doing XML parsing over the network on Android???

Thank you in advance for any help you can provide!


Solution

  • Use vtd-xml.

    Here are some benchmarks.

    Also, the emulator is extremely slow, so try it on a real device and you will likely see great improvements.