You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@daffodil.apache.org by GitBox <gi...@apache.org> on 2019/07/08 22:09:21 UTC

[GitHub] [incubator-daffodil] bsloane1650 commented on a change in pull request #259: Incremental progress on schema compilation space/speed issue.

bsloane1650 commented on a change in pull request #259: Incremental progress on schema compilation space/speed issue.
URL: https://github.com/apache/incubator-daffodil/pull/259#discussion_r301318811
 
 

 ##########
 File path: daffodil-core/src/main/scala/org/apache/daffodil/dsom/ModelGroup.scala
 ##########
 @@ -57,41 +58,54 @@ object ModelGroupFactory {
       lexicalParent.schemaDefinitionError("Model group circular definitions. Group references, or hidden group references form a loop.")
     } else {
       val moreNodesAlreadyTrying = nodesAlreadyTrying + child
+      val res = // memoizedApply(child)(lexicalParent)(position)(isHidden)(nodesAlreadyTrying)
+        nonMemoizedApply(child, lexicalParent, position, isHidden, nodesAlreadyTrying)
+      res
+    }
+  }
 
-      val childModelGroup: ModelGroup = child match {
-        case <sequence>{ _* }</sequence> => {
-          val seq = new Sequence(child, lexicalParent, position)
-          if (seq.hiddenGroupRefOption.isDefined) {
-            //
-            // construct the group ref XML, then recursively process that,
-            // but set flag so it will be hidden.
-            //
-            val hgrXML = seq.hiddenGroupRefXML
-            ModelGroupFactory(hgrXML, lexicalParent, position, true, moreNodesAlreadyTrying)
-          } else {
-            seq
-          }
-        }
-        case <choice>{ _* }</choice> => new Choice(child, lexicalParent, position)
-        case <group>{ _* }</group> => {
-          val pos = lexicalParent match {
-            case ct: ComplexTypeBase => 1
-            case mg: ModelGroup => position
-            case gd: GlobalGroupDef => position
-          }
-          val isH = isHidden || lexicalParent.isHidden
-          val groupRefFactory = new GroupRefFactory(child, lexicalParent, pos, isH)
-          val groupRefInstance = groupRefFactory.groupRef
-          groupRefInstance.asModelGroup
+  private lazy val memoizedApply =
+    Memoize1((child: Node) =>
+      Memoize1((lexicalParent: SchemaComponent) =>
+        Memoize1((position: JInt) =>
+          Memoize1((isHidden: JBoolean) =>
+            (nodesAlreadyTrying: Set[Node]) =>
+              nonMemoizedApply(child, lexicalParent, position, isHidden, nodesAlreadyTrying)))))
+
+  private def nonMemoizedApply(child: Node, lexicalParent: SchemaComponent, position: JInt, isHidden: Boolean,
 
 Review comment:
   Can we improve the name of memoizedApply and nonMemoizedApply (and probably add a comment).
   
   I get the sense that what we are "applying" is lexical component to a particular context. I assume the intent here is that it will allow us to still specialize terms when their lexical context requires it, but allows for us to use memoization to avoid re-computing terms that do not require it.
   
   One issue I see with this approach (which may be unavoidable) is that it is highly attractive for developers to add new parameters without giving much thought to exponential blowup. On that note, I see that we are dependent on lexicalParent, which seems like an overly broad dependency .

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services