Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos1 into 
lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos1/+merge/79746

Memory optimization: udf-call iterator deallocates the udf plan state 
immediately after it gets the last result from the udf. Do this for recursive 
functions only.
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos1/+merge/79746
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/functions/udf.cpp'
--- src/functions/udf.cpp	2011-10-18 17:37:41 +0000
+++ src/functions/udf.cpp	2011-10-18 22:55:31 +0000
@@ -318,7 +318,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-  PlanIter_t user_function::getPlan(CompilerCB* ccb, uint32_t& planStateSize)
+PlanIter_t user_function::getPlan(CompilerCB* ccb, uint32_t& planStateSize)
 {
   if (thePlan == NULL)
   {
@@ -353,7 +353,7 @@
 
     ulong nextVarId = 1;
     const store::Item* lName = getName();
-    //lName may be null of inlined functions
+    //lName may be null for inlined functions
     thePlan = zorba::codegen((lName == 0 ?
                               "inline function" :
                               lName->getStringValue().c_str()),

=== modified file 'src/runtime/core/fncall_iterator.cpp'
--- src/runtime/core/fncall_iterator.cpp	2011-10-18 17:37:41 +0000
+++ src/runtime/core/fncall_iterator.cpp	2011-10-18 22:55:31 +0000
@@ -121,7 +121,11 @@
 {
   thePlan = udf->getPlan(planState.theCompilerCB, thePlanStateSize).getp();
 
-  thePlanStateSize = thePlan->getStateSizeOfSubtree();
+  if (thePlanStateSize == 0)
+  {
+    thePlanStateSize = thePlan->getStateSizeOfSubtree();
+    udf->setPlaneStateSize(thePlanStateSize);
+  }
 
   // Must allocate new dctx, as child of the "current" dctx, because the udf
   // may be a recursive udf with local block vars, all of which have the same
@@ -149,7 +153,27 @@
 {
   PlanIteratorState::reset(planState);
 
-  if (thePlanOpen)
+  if (!thePlanOpen)
+  {
+    if (theLocalDCtx == NULL)
+      theLocalDCtx = new dynamic_context(planState.theGlobalDynCtx);
+
+    if (thePlanState == NULL)
+    {
+      thePlanState = new PlanState(planState.theGlobalDynCtx,
+                                   theLocalDCtx,
+                                   thePlanStateSize,
+                                   planState.theStackDepth + 1,
+                                   planState.theMaxStackDepth);
+
+      thePlanState->theCompilerCB = planState.theCompilerCB;
+#ifdef ZORBA_WITH_DEBUGGER
+      thePlanState->theDebuggerCommons = planState.theDebuggerCommons;
+#endif
+      thePlanState->theQuery = planState.theQuery;
+    }
+  }
+  else
   {
     thePlan->reset(*thePlanState);
   }
@@ -363,6 +387,19 @@
     DEBUGGER_POP_FRAME;
 #endif
 
+    if (!theIsDynamic && theUDF->isRecursive())
+    {
+      state->thePlan->close(*state->thePlanState);
+
+      delete state->thePlanState;
+      state->thePlanState = NULL;
+
+      delete state->theLocalDCtx;
+      state->theLocalDCtx = NULL;
+
+      state->thePlanOpen = false;
+    }
+
     STACK_END(state);
 
   }

=== modified file 'test/rbkt/Queries/zorba/xmark/q12.xq'
--- test/rbkt/Queries/zorba/xmark/q12.xq	2011-06-24 19:58:33 +0000
+++ test/rbkt/Queries/zorba/xmark/q12.xq	2011-10-18 22:55:31 +0000
@@ -1,10 +1,12 @@
 declare variable $input-context external;
-let $auction := doc($input-context) return
+
+let $auction := doc($input-context) 
+return
 for $p in $auction/site/people/person
 let $l :=
-for $i in $auction/site/open_auctions/open_auction/initial
-where $p/profile/@income > 5000 * exactly-one($i/text())
-return $i
+  for $i in $auction/site/open_auctions/open_auction/initial
+  where $p/profile/@income > 5000 * exactly-one($i/text())
+  return $i
 where $p/profile/@income > 50000
 return <items person="{$p/profile/@income}">{count($l)}</items>
 

=== modified file 'test/rbkt/Queries/zorba/xray/raytracer.xqlib'
--- test/rbkt/Queries/zorba/xray/raytracer.xqlib	2011-06-03 16:14:19 +0000
+++ test/rbkt/Queries/zorba/xray/raytracer.xqlib	2011-10-18 22:55:31 +0000
@@ -1,6 +1,7 @@
 module namespace raytracer="http://www.xqsharp.com/raytracer";;
 
 declare namespace math="http://www.w3.org/2005/xpath-functions/math";;
+
 import module namespace vector="http://www.xqsharp.com/raytracer/vector"; at "vector.xqlib";
 import module namespace shapes="http://www.xqsharp.com/raytracer/shapes"; at "shapes.xqlib";
 import module namespace materials="http://www.xqsharp.com/raytracer/materials"; at "materials.xqlib";

=== modified file 'test/rbkt/Queries/zorba/xray/shapes.xqlib'
--- test/rbkt/Queries/zorba/xray/shapes.xqlib	2011-06-03 16:14:19 +0000
+++ test/rbkt/Queries/zorba/xray/shapes.xqlib	2011-10-18 22:55:31 +0000
@@ -1,6 +1,7 @@
 module namespace shapes="http://www.xqsharp.com/raytracer/shapes";;
 
 declare namespace math="http://www.w3.org/2005/xpath-functions/math";;
+
 import module namespace vector="http://www.xqsharp.com/raytracer/vector";
   at "vector.xqlib";
 

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to