Project

Profile

Help

Lazy Evaluation in Saxon

Added by Anonymous about 17 years ago

Legacy ID: #4593128 Legacy Poster: Leap (leonardo06)

Hi,Michael Recently I've been reading several books and papers about compiling functional language. So far as I know, XQuery is a functional language with side effect. When applying lazy evaluation, many approaches for optimization can be implemented in compliler using equational reasoning. I want to know how lazy evaluation works in Saxon when I write a query in Stylus. As an expression is transformed to the intermediate representation in Saxon, which lazy evalution stragy should apply? Is every value of xquery expression converted to a closure with dynamic context? Or Otherwise is it difference between expressions: some expressions use direct evaluation strategy while others use lazy evaluation strategy? And which layer does Saxon apply lazy evationation, the expression layer or internal language layer? I'm eager and curious to know the stragy in Saxon and become familiar with it. Thank you for attention. Wish you best luck. A foreign Student.


Replies (4)

Please register to reply

RE: Lazy Evaluation in Saxon - Added by Anonymous about 17 years ago

Legacy ID: #4593349 Legacy Poster: Michael Kay (mhkay)

For detailed answers to these questions you will need to study the source code. Look for example at the method ExpressionTool.lazyEvaluationMode(). First, Saxon distinguishes lazy evaluation from pipelining. Pipelined evaluation of sequences is used wherever possible. Lazy evaluation as such only arises with variables (including function parameters). There are a number of heuristics applied to decide when variables should be evaluated lazily and when eagerly, some of these rules are applied at compile time and some at run time. To be honest, I don't really have a really firm idea of how effective these heuristics are - they are mainly based on a history of gradual improvement form optimizing particular queries and stylesheets - and if your studies can provide me with any feedback, that will be most welcome. Although I implemented lazy evaluation and pipelining quite early on in the development of Saxon, more recently I've been concentrating most of my optimization efforts on static rewrites. For example, inlining of variable references is more effective than lazy evaluation in the case where a variable is only referenced once. I can't immediately relate your terms "expression layer" and "internal language layer" to anything in Saxon - there's probably a mapping, but I don't think I've read the literature in which these terms are defined. Michael Kay

RE: Lazy Evaluation in Saxon - Added by Anonymous about 17 years ago

Legacy ID: #4593578 Legacy Poster: Leap (leonardo06)

Thanks for replying to me so quickly. Sorry, the two "layer" terms are not so precise. It is my guess of Saxon structure, because some implemented XQuery engine like GeoQuery translate the surface syntactics of XQuery to internal language which is a functional language using where-suffix or let-prefix sentences for the purpose of making use of sophisticated optimization strategy of functional language. After all, I need a deeply reading to the source code of Saxon. Could you give me a suggestion about where to find the relative material of XQuery Lazy Evaluation, Heuristic Evaluation Algorithms and Pipelined Evaluation of Sequence? I had been searching the papers and books relative to these concepts by Yahoo!/Google and SCI/EI for two hours, and become so tired. Hope you can give me a guide. When I suddenly read the source code of XQuery implementation. I find it difficult to mapping the XQuery implementing approach to traditional functional language implementation (using graph reduction based on combinator). If I make it more clear, I'll get a better understanding of how to implement a XQuery engine and Lazy Evaluation. Please give me a guide.

RE: Lazy Evaluation in Saxon - Added by Anonymous about 17 years ago

Legacy ID: #4593643 Legacy Poster: Michael Kay (mhkay)

Saxon also has a first phase in which expressions are reduced to a simpler form, but its "core language" is much larger than some other systems. In fact, the core language includes some constructs that are not in the surface language, such as a primitive operator first-item(x) (expressions such as x[1] or x[position()=1] are translated to this). Many XQuery engines tend to convert path expressions and filter expressions into FLWOR expressions. Saxon typically does the reverse. This is partly a result of history: many XQuery engines are built on top of relational engines that understand tuple streams, whereas Saxon started life as an XSLT/XPath processor where paths and filters were the essential concept. I'm afraid, as I said, that to find out about how Saxon works you'll really have to study the source code. I'm afraid this will take you a lot more than two hours. Remember that I'm not an academic who gets career advancement by publishing research papers - I'm an engineer who writes code, and any papers I write or publish are done in my spare time. Michael Kay

RE: Lazy Evaluation in Saxon - Added by Anonymous about 17 years ago

Legacy ID: #4593866 Legacy Poster: Leap (leonardo06)

Thank you very much! I'll read the source code in detail.

    (1-4/4)

    Please register to reply