Alan Quatermain

The Tumblog of one Jim Dovey, iOS Software Chief Architect at Kobo in Toronto, Ontario.
He Twitters, he has an , and can occasionally be found on LinkedIn or Facebook.
If you have a query, you can ask it here.

This blog contains personal opinions, and is not endorsed by any company.

93651539

AQXMLParser == Big Memory Win

I just wrote an AQXMLParser test project, along with a Ruby script which generated a 22MB XML file looking kinda like this:

<root>
   <level1 id="levelOne">
     <level2 id="levelTwo">
       <number>0</number>
     </level2>
   </level1>
   <level1 id="levelOne">
     <level2 id="levelTwo">
       <number>1</number>
     </level2>
   </level1>
 </root>

…except with 200’000 items. I then record the amount of virtual memory used by the app each time it parses a ‘number’ item, keeping track of the peak amount allocated on top of the vm usage just before the parser launched (so measures only the memory allocated from calling [parser parse] and anything internal to that routine). This means that even the 22MB for the XML data isn’t included in the output here.

Here’s the output. I think it shows that AQXMLParser is going to be *lovely* for the iPhone. Mwa-ha-haa.

Testing NSXMLParser from URL...
Parsed 200000 numbers
Peak VM usage: 128991232 bytes

Testing NSXMLParser with mapped data...
Parsed 200000 numbers
Peak VM usage: 130035712 bytes

Testing AQXMLParser...
Parsed 200000 numbers
Peak VM usage: 69632 bytes

That’s right, the NSXMLParser variant (calling xmlParseChunk() with all data at once) uses 123-124MB, while AQXMLParser (calling xmlParseChunk() with 1KB at a time, not loading all data anywhere) gets 68KB.

In short: AQXMLParser == T3h w1n!

Code is on github now.

7 notes

  1. quatermain posted this