# HG changeset patch # User drewp@bigasterisk.com # Date 1630995823 25200 # Node ID 3a6ed545357f4014c3400048e11489e5419cbe3d # Parent bcfa368e54986bb980aa2b0b62fa486d1326e334 optimization: stream stmts instead of building a Graph diff -r bcfa368e5498 -r 3a6ed545357f service/mqtt_to_rdf/inference.py --- a/service/mqtt_to_rdf/inference.py Mon Sep 06 23:20:23 2021 -0700 +++ b/service/mqtt_to_rdf/inference.py Mon Sep 06 23:23:43 2021 -0700 @@ -174,7 +174,11 @@ self.usedByFuncs = Graph() self._applyFunctions() - self.graphWithoutEvals = self.lhs.graph - self.usedByFuncs + def lhsStmtsWithoutEvals(self): + for stmt in self.lhs.graph: + if stmt in self.usedByFuncs: + continue + yield stmt def _applyFunctions(self): """may grow the binding with some results""" @@ -235,7 +239,7 @@ for bound in self.lhs.findCandidateBindings(ReadOnlyGraphAggregate([workingSet]), stats): log.debug(f'{INDENT*3} rule has a working binding:') - for lhsBoundStmt in bound.binding.apply(bound.graphWithoutEvals): + for lhsBoundStmt in bound.binding.apply(bound.lhsStmtsWithoutEvals()): log.debug(f'{INDENT*5} adding {lhsBoundStmt=}') workingSet.add(lhsBoundStmt) for newStmt in bound.binding.apply(self.rhsGraph):