Support #6192
closed![Author: Michael Kay](https://www.gravatar.com/avatar/db6526d63053f09b62e52c2da8b2230a?rating=PG&size=50&default=https%3A%2F%2Fassets.plan.io%2Fimages%2Fdefault_avatar.png)
![Assignee: Michael Kay](https://www.gravatar.com/avatar/db6526d63053f09b62e52c2da8b2230a?rating=PG&size=22&default=https%3A%2F%2Fassets.plan.io%2Fimages%2Fdefault_avatar.png)
fn:fold-right() and array:fold-right() have quadratic performance
0%
Description
fn:fold-right() and array:fold-right() have quadratic performance. See https://github.com/qt4cg/qtspecs/issues/670#issuecomment-1704326836
Updated by Michael Kay 11 months ago
For the purpose of investigation, I have simplified the test case to
fold-right(-10 to 200_000, 1, op('*'))
This is taking 2.59s with an upper bound of 100_000, or 11.24 seconds with an upper bound of 200_000 (measured using -repeat:10 on the XQuery command line)
Updated by Michael Kay 11 months ago
I tried reimplementing fold-right($input, $zero, $f)
as fold-left(reverse($input), $zero, function($x, $y){$f($y, $x))
but there is no discernible difference in performance.
Updated by Michael Kay 11 months ago
False alarm. The fold is quadratic only because the cost of BigInteger multiplication increases with the size of the integers, and this calculation is generating some extremely large integers.
Updated by Michael Kay 11 months ago
- Tracker changed from Bug to Support
- Status changed from New to Closed
Closing with no action.
Please register to edit this issue