Re: Is failed key-lookups very slow in Xalan-J 1.2?

Subject: Re: Is failed key-lookups very slow in Xalan-J 1.2?
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 22 Nov 2000 12:58:01 +0000

> My timings show that if I replace the key-lookup with an empty string,
> my code runs in 0.5 seconds (overhead from other routines), and if my
> key-function succeedes in all 66 cases for my sample file then it runs
> in about 1.0 second.  Each key-lookup returns either 0 or 1 node.
> If the key-function _fails_ in all 66 cases then it runs in 5.5
> seconds, which is rather unfortunate, since this is the default setup
> for unregistered users.
> Narrowing the scope for the key-function with a xsl:for-each around,
> did not help.

Just to alleviate a misunderstanding: using an xsl:for-each around the
call to the key function doesn't change the scope of the key function
unless the xsl:for-each selects nodes in a different document.  The
key function *always* looks throughout the entire document for nodes
matching its 'match' pattern.

I would have thought that narrowing the scope of the key will only
decrease the time involved if there are VALUENUMs that you're not
interested in at all.  If that's the case, then its best to filter
them out using the key's 'match' pattern.  For example, if there are
VALUENUMs in table0 that you are interested in *and* VALUENUMs in
the table1 that you're never interested in, then you could change the
match patten to:

<xsl:key name="price-for"

This will produce a smaller hashtable for the key, and therefore
quicker lookup times, but only if it actually matches a smaller number
of VALUENUMs than it does at the moment.

The other workaround would be to avoid using the key if you know that
its not going to return a value.  You say that it will never return a
value for unregistered users - is there any way to tell whether they
are unregistered?  Perhaps the $ACCESSCODE is an empty string, for
example?  If that were the case, you could avoid the lookups with
something like:

<xsl:template match="STIBO-PRICE">
    <xsl:when test="not($ACCESSCODE)">
      <xsl:value-of select="$PRICELESS" />
      <xsl:variable name="value" select="concat(@value,',',$ACCESSCODE)"/>
      <xsl:variable name="price" select="key('price-for', $value)"/>
        <xsl:when test="string-length($price)=0">
          <xsl:value-of select="$PRICELESS"/>
          <xsl:value-of select="$price"/>

or (better) avoid calling the template at all if it will never return
anything interesting.

The other thing is that it's always possible that this is a Xalan bug
- make sure you have the latest version and see whether the Xalan
support team can help at all - or a problem to do with the version of
the Java virtual machine that you're using - as Mike reported
yesterday, Sun's JDK 1.3 can sometimes be a lot faster than
Microsoft's JVM.

Sorry I can't be more help,


Jeni Tennison

 XSL-List info and archive:

Current Thread