Re: [xsl] XSLT 4: map serialization

Subject: Re: [xsl] XSLT 4: map serialization
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Nov 2020 15:03:44 -0000
> As for this particular example, I suspect that building an XML document
incrementally from a sequence of single elements will have performance
implications -- similar to concatenating to a string many times.
>

It's true that bottom-up construction of a tree can be very expensive because
of the need for copy operations. However, the copying can be avoided with
careful optimization. For example with inline construction like

element('A', (element('B', ()), element('C', ()))

you can avoid copying B and C when attaching them to A either by recognising
this pattern statically, or by some kind of run-time laziness.

On the Java side I've produced an API called the "sapling" model where the
functions such as element() here don't construct a full XPath-navigable tree,
but just a skeletal tree, whose construction is completed lazily the first
time it is used for XPath navigation; this avoids the repeated copying of
intermediate subtrees during construction. (I believe Javascript processor use
a similar approach to avoid string copying for repetitive string
concatenation).

Michael Kay
Saxonica

Current Thread