try catch mechanisms and inlining
Saturday, 17 January 2015 · 7 messages
JM
jean-marc Mercier17 Jan 2015 13:27 #
Hello all,
I wrote some basic debugging / profiling tools for xquery code, using try{} catch *{} mechanisms. However, profiling tools are not reliable.
The suspected reason is that inlining is not activated in try catch expression. If confirmed, is it a desired behavior ?
Here is the basic test :
declare function local:test($i){fn:for-each(1 to $i, function($a){2*$a})};
declare function local:fun-profile($fun,$args) {try{local:call($fun,$args)}
catch *{()}};
declare function local:fun-profile2($fun,$args) {local:call($fun,$args)};With default options (ie inlining activated)
prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : 683.12 ms
prof:time(count(local:fun-profile(local:test#1, 10000000))) Output : 2465.47 ms
With inlining desactivated (ie INLINELIMIT=0)
prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : 2480.32 msJM
jean-marc Mercier17 Jan 2015 15:40 #
Hello,
To complete the previous threads :
1) I forgot a definition : declare function local:call($fun,$args) {$fun($args)};
2) The same behavior seems to occurs with the following code, not involving try catch expression :
declare function local:test($i){fn:for-each(1 to $i, function($a){2*$a})};
declare variable $test := prof:time(local:test(10000000),false(),"2 :");
prof:time(count(local:test(10000000)),false(),"1 :"),count($test)Output :
2 :2508.42 ms
1 :710.51 ms
2015-01-17 13:27 GMT+01:00 jean-marc Mercier <jeanmarc.mercier at gmail.com>:
Quoted text · jean-marc Mercier · 27 lines
> Hello all, > > I wrote some basic debugging / profiling tools for xquery code, using > try{} catch *{} mechanisms. However, profiling tools are not reliable. > > The suspected reason is that inlining is not activated in try catch > expression. If confirmed, is it a desired behavior ? > > Here is the basic test : > > declare function local:test($i){fn:for-each(1 to $i, function($a){2*$a})}; > declare function local:fun-profile($fun,$args) > {try{local:call($fun,$args)} catch *{()}}; > declare function local:fun-profile2($fun,$args) {local:call($fun,$args)}; > > With default options (ie inlining activated) > > prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output > : 683.12 ms > prof:time(count(local:fun-profile(local:test#1, 10000000))) Output > : 2465.47 ms > > With inlining desactivated (ie INLINELIMIT=0) > prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output > : 2480.32 ms > >
CG
Christian Grün17 Jan 2015 17:00 #
Hi Jean-Marc,
This time, it was not that obvious to run your query (I stlil didn't find local:call). But my guess is that the try/catch query is simply slower, because catching errors simply takes time. I invite you to look into the info view; it will show you what is inlined and what is not.
Best,
Christian
Quoted text · jean-marc Mercier · 49 lines
On Sat, Jan 17, 2015 at 3:40 PM, jean-marc Mercier <jeanmarc.mercier at gmail.com> wrote: > Hello, > > To complete the previous threads : > 1) I forgot a definition : declare function local:call($fun,$args) > {$fun($args)}; > 2) The same behavior seems to occurs with the following code, not involving > try catch expression : > > declare function local:test($i){fn:for-each(1 to $i, function($a){2*$a})}; > declare variable $test := prof:time(local:test(10000000),false(),"2 :"); > prof:time(count(local:test(10000000)),false(),"1 :"),count($test) > > Output : > 2 :2508.42 ms > 1 :710.51 ms > > > > 2015-01-17 13:27 GMT+01:00 jean-marc Mercier <jeanmarc.mercier at gmail.com>: >> >> Hello all, >> >> I wrote some basic debugging / profiling tools for xquery code, using >> try{} catch *{} mechanisms. However, profiling tools are not reliable. >> >> The suspected reason is that inlining is not activated in try catch >> expression. If confirmed, is it a desired behavior ? >> >> Here is the basic test : >> >> declare function local:test($i){fn:for-each(1 to $i, function($a){2*$a})}; >> declare function local:fun-profile($fun,$args) >> {try{local:call($fun,$args)} catch *{()}}; >> declare function local:fun-profile2($fun,$args) {local:call($fun,$args)}; >> >> With default options (ie inlining activated) >> >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : >> 683.12 ms >> prof:time(count(local:fun-profile(local:test#1, 10000000))) Output : >> 2465.47 ms >> >> With inlining desactivated (ie INLINELIMIT=0) >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : >> 2480.32 ms >> >
JM
jean-marc Mercier17 Jan 2015 18:17 #
Christian,
Hi, thx for your answer, sry for forgetting local:call($fun,$args) {$fun($args)} definition. I ran the test within BaseX gui as you suggested, but it is showing a "correct" behavior (see below). Thus this point is probably due to an overhead in using eclipse.
I registered anyhow some suspicious behavior while profiling, but clearly need more time to analyze the point. I will probably come back over this topic soon if you don't mind. Note that this analysis is quite difficult to do because I can't use xquery info view for my "real" queries : the gui is freezing. It appears that it is trying to dump an enormous map with which I am working.
declare function local:test($i){fn:for-each(1 to $i, function($a){2*$a})};
declare function local:fun-profile($fun,$args) {try{$fun($args)} catch
*{()}};
declare function local:fun-profile2($fun,$args) {$fun($args)};prof:time(count(local:fun-profile(local:test#1, 10000000))) : 843.18 ms (with BaseX gui)
2015-01-17 17:00 GMT+01:00 Christian Grün <christian.gruen at gmail.com>:Quoted text · Christian Grün · 67 lines
> Hi Jean-Marc, > > This time, it was not that obvious to run your query (I stlil didn't > find local:call). But my guess is that the try/catch query is simply > slower, because catching errors simply takes time. I invite you to > look into the info view; it will show you what is inlined and what is > not. > > Best, > Christian > > > On Sat, Jan 17, 2015 at 3:40 PM, jean-marc Mercier > <jeanmarc.mercier at gmail.com> wrote: > > Hello, > > > > To complete the previous threads : > > 1) I forgot a definition : declare function local:call($fun,$args) > > {$fun($args)}; > > 2) The same behavior seems to occurs with the following code, not > involving > > try catch expression : > > > > declare function local:test($i){fn:for-each(1 to $i, > function($a){2*$a})}; > > declare variable $test := prof:time(local:test(10000000),false(),"2 :"); > > prof:time(count(local:test(10000000)),false(),"1 :"),count($test) > > > > Output : > > 2 :2508.42 ms > > 1 :710.51 ms > > > > > > > > 2015-01-17 13:27 GMT+01:00 jean-marc Mercier <jeanmarc.mercier at gmail.com > >: > >> > >> Hello all, > >> > >> I wrote some basic debugging / profiling tools for xquery code, using > >> try{} catch *{} mechanisms. However, profiling tools are not reliable. > >> > >> The suspected reason is that inlining is not activated in try catch > >> expression. If confirmed, is it a desired behavior ? > >> > >> Here is the basic test : > >> > >> declare function local:test($i){fn:for-each(1 to $i, > function($a){2*$a})}; > >> declare function local:fun-profile($fun,$args) > >> {try{local:call($fun,$args)} catch *{()}}; > >> declare function local:fun-profile2($fun,$args) > {local:call($fun,$args)}; > >> > >> With default options (ie inlining activated) > >> > >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : > >> 683.12 ms > >> prof:time(count(local:fun-profile(local:test#1, 10000000))) Output : > >> 2465.47 ms > >> > >> With inlining desactivated (ie INLINELIMIT=0) > >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : > >> 2480.32 ms > >> > > >
CG
Christian Grün17 Jan 2015 18:27 #
Hi Jean-Marc,
Quoted text · jean-marc Mercier · 4 lines
> Note that this analysis is quite difficult to > do because I can't use xquery info view for my "real" queries : the gui is > freezing. It appears that it is trying to dump an enormous map with which I > am working.
You can also print the query info with the command-line flag -V.
Hope this helps,
C.
Quoted text · jean-marc Mercier · 81 lines
> > > declare function local:test($i){fn:for-each(1 to $i, function($a){2*$a})}; > declare function local:fun-profile($fun,$args) {try{$fun($args)} catch > *{()}}; > declare function local:fun-profile2($fun,$args) {$fun($args)}; > > prof:time(count(local:fun-profile(local:test#1, 10000000))) : 843.18 ms > (with BaseX gui) > > > 2015-01-17 17:00 GMT+01:00 Christian Grün <christian.gruen at gmail.com>: >> >> Hi Jean-Marc, >> >> This time, it was not that obvious to run your query (I stlil didn't >> find local:call). But my guess is that the try/catch query is simply >> slower, because catching errors simply takes time. I invite you to >> look into the info view; it will show you what is inlined and what is >> not. >> >> Best, >> Christian >> >> >> On Sat, Jan 17, 2015 at 3:40 PM, jean-marc Mercier >> <jeanmarc.mercier at gmail.com> wrote: >> > Hello, >> > >> > To complete the previous threads : >> > 1) I forgot a definition : declare function local:call($fun,$args) >> > {$fun($args)}; >> > 2) The same behavior seems to occurs with the following code, not >> > involving >> > try catch expression : >> > >> > declare function local:test($i){fn:for-each(1 to $i, >> > function($a){2*$a})}; >> > declare variable $test := prof:time(local:test(10000000),false(),"2 :"); >> > prof:time(count(local:test(10000000)),false(),"1 :"),count($test) >> > >> > Output : >> > 2 :2508.42 ms >> > 1 :710.51 ms >> > >> > >> > >> > 2015-01-17 13:27 GMT+01:00 jean-marc Mercier >> > <jeanmarc.mercier at gmail.com>: >> >> >> >> Hello all, >> >> >> >> I wrote some basic debugging / profiling tools for xquery code, using >> >> try{} catch *{} mechanisms. However, profiling tools are not reliable. >> >> >> >> The suspected reason is that inlining is not activated in try catch >> >> expression. If confirmed, is it a desired behavior ? >> >> >> >> Here is the basic test : >> >> >> >> declare function local:test($i){fn:for-each(1 to $i, >> >> function($a){2*$a})}; >> >> declare function local:fun-profile($fun,$args) >> >> {try{local:call($fun,$args)} catch *{()}}; >> >> declare function local:fun-profile2($fun,$args) >> >> {local:call($fun,$args)}; >> >> >> >> With default options (ie inlining activated) >> >> >> >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : >> >> 683.12 ms >> >> prof:time(count(local:fun-profile(local:test#1, 10000000))) Output : >> >> 2465.47 ms >> >> >> >> With inlining desactivated (ie INLINELIMIT=0) >> >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : >> >> 2480.32 ms >> >> >> > > >
JM
jean-marc Mercier17 Jan 2015 18:37 #
Hi christian,
In this case it would be useless : it appears that the optimized query consists in dumping this big map (about 400 000 000 integers), consisting in several Giga octets of data when serialized.
2015-01-17 18:27 GMT+01:00 Christian Grün <christian.gruen at gmail.com>:
Quoted text · Christian Grün · 101 lines
> Hi Jean-Marc, > > > Note that this analysis is quite difficult to > > do because I can't use xquery info view for my "real" queries : the gui > is > > freezing. It appears that it is trying to dump an enormous map with > which I > > am working. > > You can also print the query info with the command-line flag -V. > > Hope this helps, > C. > > > > > > > > declare function local:test($i){fn:for-each(1 to $i, > function($a){2*$a})}; > > declare function local:fun-profile($fun,$args) {try{$fun($args)} catch > > *{()}}; > > declare function local:fun-profile2($fun,$args) {$fun($args)}; > > > > prof:time(count(local:fun-profile(local:test#1, 10000000))) : 843.18 ms > > (with BaseX gui) > > > > > > 2015-01-17 17:00 GMT+01:00 Christian Grün <christian.gruen at gmail.com>: > >> > >> Hi Jean-Marc, > >> > >> This time, it was not that obvious to run your query (I stlil didn't > >> find local:call). But my guess is that the try/catch query is simply > >> slower, because catching errors simply takes time. I invite you to > >> look into the info view; it will show you what is inlined and what is > >> not. > >> > >> Best, > >> Christian > >> > >> > >> On Sat, Jan 17, 2015 at 3:40 PM, jean-marc Mercier > >> <jeanmarc.mercier at gmail.com> wrote: > >> > Hello, > >> > > >> > To complete the previous threads : > >> > 1) I forgot a definition : declare function local:call($fun,$args) > >> > {$fun($args)}; > >> > 2) The same behavior seems to occurs with the following code, not > >> > involving > >> > try catch expression : > >> > > >> > declare function local:test($i){fn:for-each(1 to $i, > >> > function($a){2*$a})}; > >> > declare variable $test := prof:time(local:test(10000000),false(),"2 > :"); > >> > prof:time(count(local:test(10000000)),false(),"1 :"),count($test) > >> > > >> > Output : > >> > 2 :2508.42 ms > >> > 1 :710.51 ms > >> > > >> > > >> > > >> > 2015-01-17 13:27 GMT+01:00 jean-marc Mercier > >> > <jeanmarc.mercier at gmail.com>: > >> >> > >> >> Hello all, > >> >> > >> >> I wrote some basic debugging / profiling tools for xquery code, using > >> >> try{} catch *{} mechanisms. However, profiling tools are not > reliable. > >> >> > >> >> The suspected reason is that inlining is not activated in try catch > >> >> expression. If confirmed, is it a desired behavior ? > >> >> > >> >> Here is the basic test : > >> >> > >> >> declare function local:test($i){fn:for-each(1 to $i, > >> >> function($a){2*$a})}; > >> >> declare function local:fun-profile($fun,$args) > >> >> {try{local:call($fun,$args)} catch *{()}}; > >> >> declare function local:fun-profile2($fun,$args) > >> >> {local:call($fun,$args)}; > >> >> > >> >> With default options (ie inlining activated) > >> >> > >> >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : > >> >> 683.12 ms > >> >> prof:time(count(local:fun-profile(local:test#1, 10000000))) Output > : > >> >> 2465.47 ms > >> >> > >> >> With inlining desactivated (ie INLINELIMIT=0) > >> >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output : > >> >> 2480.32 ms > >> >> > >> > > > > > >
CG
Christian Grün17 Jan 2015 18:40 #
Quoted text · jean-marc Mercier · 3 lines
> In this case it would be useless : it appears that the optimized query > consists in dumping this big map (about 400 000 000 integers), consisting in > several Giga octets of data when serialized.
True, this doesn't always make sense (my comment was mostly pointing to your observation "The suspected reason is that inlining is not activated in try catch expression." on the query you sent to us).
Quoted text · jean-marc Mercier · 108 lines
> > 2015-01-17 18:27 GMT+01:00 Christian Grün <christian.gruen at gmail.com>: >> >> Hi Jean-Marc, >> >> > Note that this analysis is quite difficult to >> > do because I can't use xquery info view for my "real" queries : the gui >> > is >> > freezing. It appears that it is trying to dump an enormous map with >> > which I >> > am working. >> >> You can also print the query info with the command-line flag -V. >> >> Hope this helps, >> C. >> >> >> > >> > >> > declare function local:test($i){fn:for-each(1 to $i, >> > function($a){2*$a})}; >> > declare function local:fun-profile($fun,$args) {try{$fun($args)} catch >> > *{()}}; >> > declare function local:fun-profile2($fun,$args) {$fun($args)}; >> > >> > prof:time(count(local:fun-profile(local:test#1, 10000000))) : 843.18 ms >> > (with BaseX gui) >> > >> > >> > 2015-01-17 17:00 GMT+01:00 Christian Grün <christian.gruen at gmail.com>: >> >> >> >> Hi Jean-Marc, >> >> >> >> This time, it was not that obvious to run your query (I stlil didn't >> >> find local:call). But my guess is that the try/catch query is simply >> >> slower, because catching errors simply takes time. I invite you to >> >> look into the info view; it will show you what is inlined and what is >> >> not. >> >> >> >> Best, >> >> Christian >> >> >> >> >> >> On Sat, Jan 17, 2015 at 3:40 PM, jean-marc Mercier >> >> <jeanmarc.mercier at gmail.com> wrote: >> >> > Hello, >> >> > >> >> > To complete the previous threads : >> >> > 1) I forgot a definition : declare function local:call($fun,$args) >> >> > {$fun($args)}; >> >> > 2) The same behavior seems to occurs with the following code, not >> >> > involving >> >> > try catch expression : >> >> > >> >> > declare function local:test($i){fn:for-each(1 to $i, >> >> > function($a){2*$a})}; >> >> > declare variable $test := prof:time(local:test(10000000),false(),"2 >> >> > :"); >> >> > prof:time(count(local:test(10000000)),false(),"1 :"),count($test) >> >> > >> >> > Output : >> >> > 2 :2508.42 ms >> >> > 1 :710.51 ms >> >> > >> >> > >> >> > >> >> > 2015-01-17 13:27 GMT+01:00 jean-marc Mercier >> >> > <jeanmarc.mercier at gmail.com>: >> >> >> >> >> >> Hello all, >> >> >> >> >> >> I wrote some basic debugging / profiling tools for xquery code, >> >> >> using >> >> >> try{} catch *{} mechanisms. However, profiling tools are not >> >> >> reliable. >> >> >> >> >> >> The suspected reason is that inlining is not activated in try catch >> >> >> expression. If confirmed, is it a desired behavior ? >> >> >> >> >> >> Here is the basic test : >> >> >> >> >> >> declare function local:test($i){fn:for-each(1 to $i, >> >> >> function($a){2*$a})}; >> >> >> declare function local:fun-profile($fun,$args) >> >> >> {try{local:call($fun,$args)} catch *{()}}; >> >> >> declare function local:fun-profile2($fun,$args) >> >> >> {local:call($fun,$args)}; >> >> >> >> >> >> With default options (ie inlining activated) >> >> >> >> >> >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output >> >> >> : >> >> >> 683.12 ms >> >> >> prof:time(count(local:fun-profile(local:test#1, 10000000))) Output >> >> >> : >> >> >> 2465.47 ms >> >> >> >> >> >> With inlining desactivated (ie INLINELIMIT=0) >> >> >> prof:time(count(local:fun-profile2(local:test#1, 10000000))) Output >> >> >> : >> >> >> 2480.32 ms >> >> >> >> >> > >> > >> > > >
Written for BaseX 7.9. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery