This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


Thorbjørn,

> 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"
         match="table0/record0/VALUENUM"
         use="../PRICEKEY"/>

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:choose>
    <xsl:when test="not($ACCESSCODE)">
      <xsl:value-of select="$PRICELESS" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="value" select="concat(@value,',',$ACCESSCODE)"/>
      <xsl:variable name="price" select="key('price-for', $value)"/>
      <xsl:choose>
        <xsl:when test="string-length($price)=0">
          <xsl:value-of select="$PRICELESS"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$price"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

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

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]