mbeckerle 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_r301356286
########## 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: I removed all the memoize stuff, as it wasn't being used, and your observations are very apropos. Memoize approaches work best when the equality comparison work involved is well understood to be either pointer-based equality or operating on simple values or simple tuples of values. This was half baked, and not in use as yet, so I removed it for now. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services