Re: [xml] Performance of DOM interface



Daniel Veillard wrote:
On Sat, Aug 24, 2002 at 03:13:08PM +0200, wellnhofer aevum de wrote:

Hi,

I'm using libxml and libxslt with Perl to generate dynamic HTML pages and did some performance testing recently. I created a XML tree from a Perl data structure using the DOM interface and transform that tree with XSLT.

While the performance of the XSLT transformation is really good, I found that constructing the DOM tree took about 75% of the running time. So it takes about three times longer to create the XML source tree than to parse a stylesheet and apply and output the transformation.

Is this behavior normal? I would think creating an XML tree is much faster than a XSLT transformation.


  Well usually when creating the input tree using directly the C parser,
the parse time (which includes building the DOM tree) is quite smaller than
the tranformation time itself. So no it's not "normal", though it also depends a lot on the stylesheet used too. You're probably paying the cost of going back and forth between the Perl and the C library for each call to DOM entry points.

Yes, that seems to be the only explanation I can think of. The XSLT transformation needs about 5 calls to the C library, but the creation of the DOM tree requires hundreds of calls of createElement and appendChild.

It might even be faster to generate XML directly in Perl and write it to a file or memory buffer and then parse it with libxml again. I think I will try that, although it seems like a stupid approach.

The best solution is probably a single Perl XS function that converts a whole Perl data structure to a DOM tree in one go.

Nick Wellnhofer




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]