lazy compilation of imported functions?
Added by Anonymous almost 17 years ago
Legacy ID: #4708128 Legacy Poster: Chapman Flack (jcflack)
Hi, I've put together a tool for (semi-)interactively querying several data sources, and to make it less burdensome for the user there are several modules of useful XQuery functions imported by default (the tool prepends the 'import module' requests to the user's query). The tool's startup time is longer than I would like, and looking at some 'explain' output I noticed what appeared to be fully compiled/optimized representations of all of the functions defined in those modules, whether or not reachable in any way from the main query. Is there any way (preferably in Saxon-B) to have functions declared in imported modules analyzed/optimized/compiled more lazily, say only when Saxon determines they can be called? (Hmm, I guess even a statically-unreachable function could be called by Java code, so maybe in that case the first call could trigger analysis.) Another alternative could be a way to generate a pre-"compiled" form of an XQuery module that can be imported more quickly than XQuery source code. I'm guessing a little laziness would be the easier feature to add, but either one could take some of the sting out of developing an importable library of functions. (I guess anything I've said about 'functions' should go for the initializing expressions of imported variables too.) Chapman Flack
Replies (3)
Please register to reply
RE: lazy compilation of imported functions? - Added by Anonymous almost 17 years ago
Legacy ID: #4708164 Legacy Poster: Michael Kay (mhkay)
It's a reasonable suggestion, and is in fact not difficult (Saxon currently goes to some trouble to make sure that unreferenced functions are compiled, solely to support the fact that they can be called directly from Java). The obvious answer is a compile time flag to indicate that functions should be callable from Java, set to false by default - I think we can take the compatibility hit for the relatively few people using this feature. Separate compilation of modules would of course be another useful step forwards, but is rather harder to achieve, especially the issue of comparing schema consistency.
RE: lazy compilation of imported functions? - Added by Anonymous almost 17 years ago
Legacy ID: #4708170 Legacy Poster: Michael Kay (mhkay)
I should point out of course that Saxon is obliged to report all static errors in functions even if they are never called, so it won't be possible to eliminate all the compile-time work. It would be interesting to have some measurement as to how much the start-up time is reduced if you remove the unused functions from the compilation - that gives an upper bound on the saving that might be possible.
RE: lazy compilation of imported functions? - Added by Anonymous almost 17 years ago
Legacy ID: #4708248 Legacy Poster: Michael Kay (mhkay)
I've taken a look at it and unfortunately it's not so easy at all. Some of the checks that the specification requires (for example the checks requiring consistency between the schema imported into a calling module and the schema imported into a called module) are done at quite a late stage of the compilation process, and it would be non-conformant to omit these checks even for a function that is never called. Other phases of compiling a function body are done before it is known whether there are any calls to a function or not. So it doesn't look as if there are any easy savings here.
Please register to reply