in reply to Perl_XML Twig Performance query

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.

Replies are listed 'Best First'.
Re^2: Perl_XML Twig Performance query
by mirod (Canon) on Apr 23, 2010 at 00:15 UTC

    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".

Re^2: Perl_XML Twig Performance query
by Anonymous Monk on Jun 16, 2010 at 18:54 UTC
    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.