cloudify-dsl-parser icon indicating copy to clipboard operation
cloudify-dsl-parser copied to clipboard

Accelerate the speed of parsing blueprint

Open lin344902118 opened this issue 6 years ago • 0 comments

dsl_parser/framework/parser.py between line 207 to 242 def _calculate_element_graph(self): self.element_graph = nx.DiGraph(self._element_tree) for element_type, _elements in self.element_type_to_elements.items(): requires = element_type.requires for requirement, requirement_values in requires.items(): requirement_values = [ Requirement(r) if isinstance(r, basestring) else r for r in requirement_values] if requirement == 'inputs': continue if requirement == 'self': requirement = element_type dependencies = self.element_type_to_elements.get( requirement, []) predicates = [r.predicate for r in requirement_values if r.predicate is not None]

            if not predicates:
                dep = _BatchDependency(element_type, requirement)
                for dependency in dependencies:
                    self.element_graph.add_edge(dep, dependency)
                for element in _elements:
                    self.element_graph.add_edge(element, dep)
                continue

            for dependency in dependencies:
                for element in _elements:
                    add_dependency = all([
                        predicate(element, dependency)
                        for predicate in predicates])
                    if add_dependency:
                        self.element_graph.add_edge(element, dependency)
    # we reverse the graph because only netorkx 1.9.1 has the reverse
    # flag in the topological sort function, it is only used by it
    # so this should be good
    self.element_graph.reverse(copy=False)

I think can create a map to cache the element which is most used. This can accelerate the speed of parsing blueprint.

lin344902118 avatar Sep 17 '19 12:09 lin344902118