Skip to content
This repository has been archived by the owner on Oct 5, 2020. It is now read-only.

Accelerate the speed of parsing blueprint #143

Open
lin344902118 opened this issue Sep 17, 2019 · 0 comments
Open

Accelerate the speed of parsing blueprint #143

lin344902118 opened this issue Sep 17, 2019 · 0 comments

Comments

@lin344902118
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant