This performance bug was reported in
It turns out to be a problem that was present in the
code in Saxon 8.4, but had never been noticed - it
didn't affect this particular query because of slight
(and essentially irrelevant) differences in the query
The MemoClosure class is supposed to delay evaluation
of an expression, and then remember the value when it
is eventually evaluated, so that it never needs to be
computed more than once. However, there is one method
in MemoClosure, materialize(), which in certain states
evaluates the expression without remembering the value,
so that it is re-evaluated on each call.
It's not possible to describe in source query terms
what conditions are likely to trigger this problem. In
manycases it's likely that the effect on performance
will not even be noticeable.
Attached is a replacement version of the
net.sf.saxon.value.MemoClosure.java module that fixes
the problem. For use only with Saxon 8.5.