Re: Pulling v/s Pushing
Aleksander Slominski <[email protected]>
| Newsgroups | gmane.text.xml.xmlpull.devel |
|---|---|
| Message-ID | <[email protected]> |
"Nikhil C. Khedkar" wrote: > Hi Alec, > those links proved very useful in knowing what is > pulling v/s pushing. Thanks for that. But I still have > few questions > 1) what makes pulling faster than pushing? I mean if > your program gets the control from parser, how does it > help? Where was the parser lagging? hi, when you construct parser you have (more or less) following layers * input reading/decoding/buffering * tokenizer * streaming API: both push and pull (like SAX and XmlPull) * in-memory API (like DOM, JDOM etc.) both push pull parser APIs are typically very close to tokenizer and therefore can be efficient - i do not think that there is any inherent difference in performance between push and pull parsing. one important observation is that it is very easy to implement push API on top of pull API but not vice versa so if you need to use both APIs when working on the same XML input just having pull API may be enough to get push API working too (we have SAX2 driver that works on top of XmlPull API). however in my opinion the main difference is in the application code that uses push or pull API: if your XML processing is more of filtering/selecting parts of XML then push API may be the best. but if you need to process whole XML input you will find that pull API is much easier to use compared to push parsing as much less extra code is required to manage application state. in push parsing application needs to manage state between callbacks and that easily can become tricky and requires lot of careful coding to make it efficient - in extreme cases may require hard to debug and maintain complex state machines. for example consider case of parsing XML document that has sequence of items (price list) and each item consists of name and few additional properties (delivery/prices), take a look on: http://www-106.ibm.com/developerworks/xml/library/x-saxapi/ and compare SAX code that even for this simple XML input requires 5 states and switch() code in callbacks to manage state transitions efficiently: http://www-106.ibm.com/developerworks/xml/library/x-saxapi/listing4.html with equivalent XmlPull implementation (it is also in samples directory) http://www.xmlpull.org/v1/download/unpacked/src/java/samples/BestDeal.java that simply processes input when it is ready to do it, application code directly mirrors what is algorithm to find best vendor without need to have any extra state except to maintain information about best deal (checkVendor: method) > 2) Why do the comaprsion with SAX2 vary so much and > why do pull parser loose it's edge for large > documents? as always all depends on actual implementation. when i have implemented XPP2/XPP3 my main focus was for fast parsing of small/medium size SOAP messages (from my experience XML does not seem to good to send big data blocks ...) and i think there are possible implementations with different perfromance requirements (ex. that works very well for large docs) > 3) What is roundtrip? it is ability of parser to provide enough information (beyond XML infoset) to be able to reproduce exactly input XML document. thanks, alek