Dear members, dear Christian,

when using a for-loop inside of a for-loop I run into serious 
performance-problems, when I'm using variables to return results.
For example this code-line takes 36780ms (!!!) for evaluation:

return  <li><a>{$title}</a>{$quote}</li>

When I substitute the variable $time with the defining code, it takes only 
711ms for evaluation (!!):

<li><a>
{ if ($ele/ancestor::tei:TEI//tei:titleStmt/tei:title[@type="short"]) then 
$ele/ancestor::tei:TEI//tei:titleStmt/tei:title[@type="short"]/string()
        else if 
($ele/ancestor::tei:TEI//tei:titleStmt/tei:title[@type="article"]) then 
$ele/ancestor::tei:TEI//tei:titleStmt/tei:title[@type="article"]/string()
        else if ($ele/ancestor::tei:TEI//tei:titleStmt/tei:title[@type="main"]) 
then $ele/ancestor::tei:TEI//tei:titleStmt/tei:title[@type="main"]/string()
        else ()}
</a>{$quote}</li>

The only difference in the code is using a variable and it differs in 
performance by a factor of more than 50. In my real application (using more 
variables) it differs by factor more than 150.

I tried to simulate the problem with a simple factbook-query. Here is the code:
xquery version "3.0";
let $query := "Pa.*"
for $city in doc('factbook')//city/name
 for $hits in ft:mark($city[.//text() contains text {$query} using wildcards])
 let $country_of_city := $city/ancestor::country/name
 return
 (: fast version: Evaluating 12.54ms :)
 
<hit><city>{$hits}</city><country>{$city/ancestor::country/name}</country></hit>

 (: slow version: Evaluating 35.78 :)
 (: <hit><city>{$hits}</city><country>{$country_of_city}</country></hit> :)

Also here is a performance bottleneck (not as dramatically: factor 3). Is there 
any solution to the problem? Now I'm working in my code without variables in 
the result part of the xquery, but it makes realy ugly non maintainable code.

Any help would be appreciated.
- Günter

Reply via email to