amazingly this is true
I've just ran a comparison on a set of 20,000 nodes and the results
were near identical....
I will now freely use ancestor with a clear conscience!
So how can getting the parent of each node in the ancestry be as fast
as essentially not getting the parent of each node (tunnelled
parameters cant cost anywhere near as much)? Is there trickery
No trickery, just code. I can only suggest you study the relevant paths in
the Saxon source code.
When the tree is a TinyTree, Saxon represents nodes using a transient
TinyNodeImpl object: usually, depending on the path by which the node was
reached, this will contain a reference to the TinyNodeImpl object
representing the node's parent in the tree. So following the ancestor axis
just involves one pointer dereference for each step along the axis, plus a
test to see whether the node satisfies the required Nodetest: for a node
test of the form ancestor::A, this is essentially two integer comparisons,
one to check that you've found an element node and one to check the name.
Tunnel parameters involve a small overhead on every template call. The set
of tunnel parameters passed to (or through) a template is held in a hash
table (indexed by parameter name represented as an integer code) which is
referenced from the stack frame for the template; this hash table is copied
on each call to make sure that changes don't affect the caller. There's
scope for optimization here (for example, one could avoid copying the hash
table when this isn't necessary, or one could do a long search down the
stack when accessing a tunnel parameter so that there is zero work in
passing them along). Currently the only case that's optimized is the case
where there are no tunnel parameters at all.
Part of the lesson here is simply that features that are used more
frequently tend, over time, to be more heavily optimized. Tunnel parameters
have not yet featured in any benchmarks...
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>