niranjan_ng has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Perl_XML Twig Performance query
by ikegami (Patriarch) on Apr 22, 2010 at 20:42 UTC

    XML::Twig uses XML::Parser (Expat) to parse XML, but XML::Parser is just not that fast of a parser.*

    SOAP::Lite uses XML::Parser as well. I wrote a patch that makes SOAP::Lite use XML::LibXML. Including the time it takes to convert XML::LibXML's output to XML::Parser's format, XML::LibXML was 12x faster.

    Rate Expat LibXML Expat 9.09/s -- -92% LibXML 118/s 1202% --

    Now, XML::LibXML is not a good solution for XML::Twig since XML::Twig is designed to work with huge documents and streams, but maybe XML::Twig is not the best solution for you.

    * — It blows off the pants off every alternative I tried as the backend for XML::Simple, so it's not exactly a slouch either.

      I am not sure that libxml2 is much faster than expat, I think the difference in speed between XML::Parser based and XML::LibXML based modules is that XML::Parser converts all of the data to Perl data structures while XML::LibXML, at least in its DOM mode, leaves everything in C-land. So a module like XML::Twig needs to build and manage a tree in Perl, while XML::LibXML relies a lot more on the underlying C library, which unsurprisingly is faster and uses less memory.

      But when you use XML::LibXML as the backend for XML::Simple, then you have to convert all the data into Perl, and you loose those benefits.

        I guess I wasn't clear. XML::LibXML was 12x faster than XML::Parser at creating exactly the same Perl data structure as XML::Parser. Nothing was left in "C-land".

        I guess I wasn't clear. XML::LibXML was 12x faster than XML::Parser at creating exactly the same Perl data structure as XML::Parser. Nothing was left in "C-land".

      Now, XML::LibXML is not a good solution for XML::Twig since XML::Twig is designed to work with huge documents and streams, but maybe XML::Twig is not the best solution for you.
      Take a look at XML::LibXML::Reader. It's perfect for working with large documents.
Re: Perl_XML Twig Performance query
by sierpinski (Chaplain) on Apr 22, 2010 at 19:17 UTC
    Please edit your post and reformat using the code tags or other formatting tags. It's extremely difficult to read.
Re: Perl_XML Twig Performance query
by igelkott (Priest) on Apr 22, 2010 at 19:26 UTC

    please use code-tags for formatting your code