Why is Android XmlPullParser REALLY slowing down on my older device?

I used a simple XML parser, using the official Android manual on XmlPullParser , to XmlPullParser very simple and short XML file (120 lines, 10.5Kb). On my HTC One X running Android 4.1.1, it takes a fraction of a second to analyze it. But on my HTC Hero running Android 2.1, it took more than 3 minutes ...

I know that the hardware between 2 is very different, but 3 minutes for such a small file? This is unacceptable ... Especially since XmlPullParser is available with API 1, it makes no sense to be so slow.

To try to identify the problem, I went through the analysis code step by step. And I noticed that nextTag() is the one that takes a very long time to process, everything else seems very fast. Dunno if this is the only problem or not ...

Any ideas how I can fix this?

+4
source share
1 answer

After more thorough debugging and research, I realized that the problem was not with XmlPullParser , as I suspected, it just didn't make any sense ...

The real problem was that I parsed the date and used SimpleDateFormat , specifying a different language than the one currently in use. Android versions below ICS (if I'm not mistaken) have serious errors with this and take a long time to download the necessary locale information for SimpleDateFormat . These versions load and cache the standard system locale (user settings) and Locale.US when the system boots, and if any of these locales is used with SimpleDateFormat , the operation is quick. Otherwise, it’s slow as hell.

I also created a new instance of SimpleDateFormat for each date parsing, which was unnecessary and stupid. Using a single object as an instance variable reduced the time required to parse the file.

+4
source

All Articles