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
xmlParseChunk() with 1KB at a time, not loading all data anywhere) gets 68KB.
In short: AQXMLParser == T3h w1n!
Code is on github now.