Эх сурвалжийг харах

remove expensive check from schema solve

this commit removes the function is_signature_in_other_signature
because profiling revealed it was slow
instead we simply store if the node was created in a schema or not
which is just a simple bool
Joseph Brandenburg 2 долоо хоног өмнө
parent
commit
84baf81de8

+ 2 - 0
base_definitions.py

@@ -742,6 +742,7 @@ class MantisNode:
         "unmet_hierarchy_dependency_count",
         "prepared", "executed", "execution_prepared",
         "socket_templates", "mContext",
+        "is_schema_prototype"
         )
     node_type='UNINITIALIZED'
     def __init__(self, signature : tuple,
@@ -762,6 +763,7 @@ class MantisNode:
         #  again without changing the readtree code much.
         self.socket_templates = socket_templates
         self.mContext = None # for now I am gonna set this at runtime
+        self.is_schema_prototype = False
         # I know it isn't "beautiful OOP" or whatever, but it is just easier
         # code should be simple and do things in the simplest way.
         # in the future I can refactor it, but it will require changes to 100+

+ 23 - 15
execution/readtree.py

@@ -74,7 +74,7 @@ def make_connections_to_ng_dummy(base_tree, tree_path_names, local_mantis_nodes,
             else:
                 prRed("No available auto-generated class for input %s in %s" % (inp.name, np.name))
 
-def gen_mantis_nodes(base_tree, current_tree, tree_path_names, mContext, all_mantis_nodes, local_mantis_nodes, dummy_nodes, group_nodes, schema_nodes ):
+def gen_mantis_nodes(base_tree, current_tree, tree_path_names, mContext, all_mantis_nodes, local_mantis_nodes, dummy_nodes, group_nodes, schema_nodes, in_schema ):
     from ..internal_nodes import DummyNode
     for ui_node in current_tree.nodes:
         if ui_node.bl_idname in ["NodeFrame", "NodeReroute"]:
@@ -115,8 +115,9 @@ def gen_mantis_nodes(base_tree, current_tree, tree_path_names, mContext, all_man
         mantis_node.mContext = mContext
         if mantis_node.signature[0] not in ['MANTIS_AUTOGENERATED'] and mantis_node.node_type not in ['SCHEMA', 'DUMMY', 'DUMMY_SCHEMA']:
             mantis_node.fill_parameters()
+        mantis_node.is_schema_prototype = in_schema
 
-def data_from_tree(base_tree, tree_path, mContext, dummy_nodes, all_mantis_nodes, all_schema):#
+def data_from_tree(base_tree, tree_path, mContext, dummy_nodes, all_mantis_nodes, all_schema, in_schema):#
     # TODO: it should be relatively easy to make this use a while loop instead of recursion.
     local_mantis_nodes, group_nodes = {}, []
     tree_path_names = [tree.name for tree in tree_path if hasattr(tree, "name")]
@@ -126,9 +127,11 @@ def data_from_tree(base_tree, tree_path, mContext, dummy_nodes, all_mantis_nodes
         current_tree = base_tree
     #
     if current_tree: # the node-group may not have a tree set - if so, ignore it.
+        if not in_schema:
+            in_schema = current_tree.bl_idname in ['SchemaTree']
         from ..utilities.utilities import clear_reroutes
         links = clear_reroutes(list(current_tree.links))
-        gen_mantis_nodes(base_tree, current_tree, tree_path_names, mContext, all_mantis_nodes, local_mantis_nodes, dummy_nodes, group_nodes, all_schema)
+        gen_mantis_nodes(base_tree, current_tree, tree_path_names, mContext, all_mantis_nodes, local_mantis_nodes, dummy_nodes, group_nodes, all_schema, in_schema)
 
         from ..utilities.utilities import link_mantis_nodes
         for link in links:
@@ -138,7 +141,7 @@ def data_from_tree(base_tree, tree_path, mContext, dummy_nodes, all_mantis_nodes
             insert_default_values_base_tree(base_tree, all_mantis_nodes)
         # Now, descend into the Node Groups and recurse
         for mantis_node in group_nodes:
-            data_from_tree(base_tree, tree_path+[mantis_node.ui_node], mContext, dummy_nodes, all_mantis_nodes, all_schema)
+            data_from_tree(base_tree, tree_path+[mantis_node.ui_node], mContext, dummy_nodes, all_mantis_nodes, all_schema, in_schema)
     return dummy_nodes, all_mantis_nodes, all_schema
 
 STRING_PADDING = 4
@@ -283,15 +286,6 @@ def solve_schema_to_tree(mantis_node, all_mantis_nodes, roots=[], error_popups=F
         solved_nodes = {}
         mantis_node.base_tree.hash=''
         raise execution_error_cleanup(mantis_node, e, show_error=error_popups)
-
-    # maybe this should be done in schema solver. TODO invesitigate a more efficient way
-    del_me = []
-    for k, v in all_mantis_nodes.items():
-        # delete all the schema's ui_node and interface nodes. The links have already been deleted by the solver.
-        if v.signature[0] not in ['MANTIS_AUTOGENERATED'] and is_signature_in_other_signature(mantis_node.signature, k):
-            del_me.append(k)
-    for k in del_me:
-        del all_mantis_nodes[k]
     for k,v in solved_nodes.items():
         all_mantis_nodes[k]=v
         init_connections(v)
@@ -433,7 +427,15 @@ def parse_tree(base_tree, error_popups=False):
     #  then they stick around because the function definition inits them once and keeps a reference
     # so instead I have to supply them to avoid ugly code or bugs elsewhere
     # it's REALLY confusing when you run into this sort of problem. So it warrants four entire lines of comments!      
-    dummy_nodes, all_mantis_nodes, all_schema =  data_from_tree(base_tree, tree_path = [None], mContext=mContext, dummy_nodes = {}, all_mantis_nodes = {}, all_schema={})
+    dummy_nodes, all_mantis_nodes, all_schema =  data_from_tree(
+        base_tree,
+        tree_path = [None], 
+        mContext=mContext,
+        dummy_nodes = {},
+        all_mantis_nodes = {},
+        all_schema={},
+        in_schema=False
+        )
     for dummy in dummy_nodes.values():    # reroute the links in the group nodes
         dummy.reroute_links(all_mantis_nodes)
     prGreen(f"Pulling data from tree took {time.time() - data_start_time} seconds")
@@ -637,7 +639,12 @@ def sort_execution(nodes, error_popups):
     sorted_nodes = []
     # initialize the hierarchy dependency count. We'll use this to ensure there
     # are no cycles (using Kahn's algorithm).
+    expected_sort_quantity = len(nodes)
     for mantis_node in nodes.values():
+        if mantis_node.node_type in ['DUMMY', 'DUMMY_SCHEMA', 'INTERFACE']:
+            expected_sort_quantity -=1 ; continue
+        if mantis_node.is_schema_prototype:
+            expected_sort_quantity -= 1; continue
         mantis_node.unmet_hierarchy_dependency_count = len(mantis_node.hierarchy_dependencies)
         if mantis_node.unmet_hierarchy_dependency_count == 0 :
             xForm_pass.append(mantis_node)
@@ -653,7 +660,7 @@ def sort_execution(nodes, error_popups):
             child.unmet_hierarchy_dependency_count-= 1
             if child.unmet_hierarchy_dependency_count == 0:
                 xForm_pass.append(child)
-    if processed_count < len(nodes):
+    if processed_count < expected_sort_quantity:
         cycle = []
         for n in nodes.values():
             if n.execution_prepared == False:
@@ -662,6 +669,7 @@ def sort_execution(nodes, error_popups):
         e = GraphError("Detected a cycle in the tree, containing at "
                          "least one of the following nodes: " + print_cycle(cycle))
         e = execution_error_cleanup(cycle[-1], e, show_error=error_popups)
+        prRed(processed_count, expected_sort_quantity)
         raise e
     return sorted_nodes, execution_failed