Hello,

I am facing some performances issues, probably due to unexpected query reevaluation. Might it be due to the optimizer ? Here is a code to test

declare function local:test($i){
    let $data := fn:for-each(1 to 10000000, function($a){2*$a} )
 (:     let $data := xquery:eval("fn:for-each(1 to 10000000, function($a){2*$a} )") :)
     return (1 to $i) ! local:test2($data,.)
};

declare function local:test2($data, $dummy) { count($data) };

(1 to 10) ! prof:time(local:test(.))

Output :

683.76 ms
1137.95 ms
1727.68 ms
2151.06 ms
2694.84 ms
3189.57 ms
3725.1 ms
4277.51 ms
4815.74 ms
5417.79 ms

Note that using xquery:eval (toggling the comment inside local:test). seems to perform correctly. However I can't use this trick as a workaround.

(1 to 10) ! prof:time(local:test(.))
Ouput : 

2472.71 ms
825.61 ms
3013.14 ms
986.81 ms
2982.97 ms
778.24 ms
1195.33 ms
3280.7 ms
976.96 ms
913.69 ms