Way to detect if saxon:memo-function is caching?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Way to detect if saxon:memo-function is caching?

David Rudel
Is there a way to detect whether saxon:memo-function="yes" is working as expected?

I have a script parsing lots of data that uses H:mm format for time and I'm using a function to convert to the two-digit format. 

When I have the script simply dump the H:mm value directly without converting it, my script takes about 6 seconds to run through 1 million rows of data.

Each H:mm string shows up about 3000 times.

When I convert the string, the script takes about 12 seconds, regardless of whether saxon:memo-function="yes" is set or not. I'd expect the saxon:memo-function version to do better.



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Way to detect if saxon:memo-function is caching?

David Rudel
Please disregard my email. I realized why I was not getting the performance improvement.

On Thu, Mar 17, 2016 at 11:34 PM, David Rudel <[hidden email]> wrote:
Is there a way to detect whether saxon:memo-function="yes" is working as expected?

I have a script parsing lots of data that uses H:mm format for time and I'm using a function to convert to the two-digit format. 

When I have the script simply dump the H:mm value directly without converting it, my script takes about 6 seconds to run through 1 million rows of data.

Each H:mm string shows up about 3000 times.

When I convert the string, the script takes about 12 seconds, regardless of whether saxon:memo-function="yes" is set or not. I'd expect the saxon:memo-function version to do better.



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Way to detect if saxon:memo-function is caching?

Michael Kay
In reply to this post by David Rudel
The only way I can think to observe it is with a TraceListener.

Here's a little test:

<xsl:stylesheet version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:f="http://local.functions/"
  exclude-result-prefixes="xs f"
  expand-text="yes">
 
 
<xsl:function name="f:memo" as="xs:integer"  cache="yes">
   
<xsl:param name="in"/>
   
<xsl:sequence select="$in+1"/>
 
</xsl:function>
 
 
<xsl:template name="xsl:initial-template">
   
<out>
     
<xsl:for-each select="1 to 100">
       
<in>{f:memo(. mod 10)}</in>
     
</xsl:for-each>
   
</out>
 
</xsl:template>
 
</xsl:stylesheet>

Running this with options

-xsl:test.xsl -t -it -T

I get the trace:

<trace saxon-version="9.7.0.4" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template name="xsl:initial-template" line="13" column="45" module="test.xsl">
  <LRE name="out" line="14" column="10" module="test.xsl">
   <xsl:for-each line="15" column="39" module="test.xsl">
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
     <xsl:function name="f:memo" line="8" column="60" module="test.xsl">
      <xsl:sequence line="10" column="35" module="test.xsl">
      </xsl:sequence>
     </xsl:function>
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>
    <LRE name="in" line="16" column="13" module="test.xsl">
    </LRE>

Showing clearly that the function body is executed on the first 10 calls, and is not executed thereafter.

That's with the standard trace listener; with a custom trace listener you could observe the effect more selectively. I suspect that the function call itself generates a call on the trace listener but the standard trace listener ignores it silently; if that's so then you should be able to detect a function call followed immediately by a function return with no notification of function entry and exit.

Michael Kay
Saxonica


On 17 Mar 2016, at 22:34, David Rudel <[hidden email]> wrote:

Is there a way to detect whether saxon:memo-function="yes" is working as expected?

I have a script parsing lots of data that uses H:mm format for time and I'm using a function to convert to the two-digit format. 

When I have the script simply dump the H:mm value directly without converting it, my script takes about 6 seconds to run through 1 million rows of data.

Each H:mm string shows up about 3000 times.

When I convert the string, the script takes about 12 seconds, regardless of whether saxon:memo-function="yes" is set or not. I'd expect the saxon:memo-function version to do better.



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...