Re: Function memoization
Dimitre Novatchev <[email protected]>
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Message-ID | <[email protected]> |
Subject: Re: Function memoization To: [email protected] > If the function is called again with the same values for the arguments, > it MUST return the remembered result. > It MUST NOT re-execute the function body, as this can cause different > results in some cases. We must define well what "the same values for the arguments" means. It is impractical to remember and compare long sequences -- this may require excessive amounts of memory and may lead to slower execution than without any memoisation. I have discussed this problem with Michael Kay before. A compromise we agreed upon was not to memorize every sequence-argument but just the ID of the sequence. Using this approach, if we pass to the function the same sequence (having the same ID) allong with all other arguments' values being as on the same previous function evaluation, then the function body will not be executed and the stored result will be returned. However, if a sequence is passed with a different ID, the function body will be executed -- although the values of the items of the passed sequence may be identical to the values of the items of a sequence that was previuosly passed as that argument, but has a different ID. Cheers, Dimitre Novatchev "Colin Paul Adams" <[email protected]> wrote in message news:[email protected]... >>>>>> "James" == James Fuller <[email protected]> writes: > > >> modified form, a proposal that Dimitre Novatchev originally > >> requested for memomizing xsl:functions. > > >> The modification being that the memoization reqest be an > >> extension instruction actually present within the xsl:function > >> concerned (this seems to me necessary to preserve compliance > >> with the specifications - user-defined data elements and > >> extension attributes may not cause a different final result > >> tree to be produced, and, in some cases, memoization of a > >> function will do just that). > > > James> I am interested in such a function as well. > > OK. I shall try to define it's semantics: > > func:memoize will be an extension instruction. No attributes. Only > permitted contents is an xsl:fallback child. > > The instruction must be an immediate child of an xsl:function or > func:function. > Good style suggests placing this immediately after the xsl:params, or > at the very end of the function body - but I do not think we need > mandate any such placement (except xsl:param must come first, as now). > > An XSLT processor that supports func:memoize shall remember the > results of any calls to functions marked with a call to > func:memoize. If the function is called again with the same values for the > arguments, > it MUST return the remembered result. > It MUST NOT re-execute the function body, as this can cause different > results in some cases. > > > -- > Colin Adams > Preston Lancashire Cheers, Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com