Project

Profile

Help

Support #6192

closed

fn:fold-right() and array:fold-right() have quadratic performance

Added by Michael Kay 11 months ago. Updated 11 months ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Performance
Sprint/Milestone:
-
Start date:
2023-09-03
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
11, 12, trunk
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

fn:fold-right() and array:fold-right() have quadratic performance. See https://github.com/qt4cg/qtspecs/issues/670#issuecomment-1704326836

Actions #1

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)

Actions #2

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.

Actions #3

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.

Actions #4

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

Also available in: Atom PDF