Hi Mark,
(I'm passing this on to the mailing list..)
At the moment my function block is not very long. But I expect this is likely to change, as I'm using XQuery as a sort of programming language where 'users' can add functions. Moreover, there will be cases where they'll be executing thousands of queries and the total execution time should ideally take no more than a second or two in the most extreme circumstance.
At this time I don't experience any performance problems, BaseX is very snappy. But I'm still in the experimentation phase and I'd like to avoid spending a lot of time building a framework that later may turn out to be unworkably slow.
Regarding the complexity and size of function blocks, our users haven't reported any bottlenecks yet. Instead, bad performance is mainly due to XQuery expressions that are difficult, or impossible, to optimize. But, no doubt, it might make sense to precompile complex XQuery code that takes hundreds of KB, or even MB. Right now, precompilation of XQuery code isn't supported in BaseX
Another thing I ran into is that updating doesn't seem to be allowed within functions. So I'm now looking into using XSLT to solve these issues for me. On the one hand by prefixing the query with the function declarations that are actually used in the query, and through templates that would substitute updating function-calls by the function-body. I'm also new to XSLT so I'm not sure if that will work, but it seems worth giving it a try.
Updating is no problem in XQuery functions: you'll have to add the "updating" specified to a function declaration:
declare updating function ... { ... };
A general restriction of XQuery is that an expression cannot both update and output items. As an example, the following query is invalid:
delete //node, 1 to 10
Instead, you can perform local updates by applying the transform expression:
copy $a := ...nodes to be modified... modify ...update on $a... return ...e.g., $a...
P.S. extracting the xsl-stylesheet from the file-header from an XML file and then applying it to itself is a bit ugly, does anyone know if there is a (JAXP) way to get an XML file with its stylesheet already applied automagically?
Maybe this won't be necessary anymore..
Hope this helps, Christian