Explorar o código

remove excess function call in schema

this commit cuts function calls by >30k in my stego test graph
Joseph Brandenburg hai 2 semanas
pai
achega
2fb4c48324
Modificáronse 1 ficheiros con 26 adicións e 25 borrados
  1. 26 25
      execution/schema_solve.py

+ 26 - 25
execution/schema_solve.py

@@ -90,11 +90,11 @@ class SchemaSolver:
     # Using lambdas here causes a lot of function calls, should be optimized out
     # since after all this only needs to change when the index updates
     def set_index_strings(self):
-        self.index_str = lambda : '.'+str(self.uuid)+'.'+str(self.index).zfill(4)
-        self.prev_index_str = lambda : '.'+str(self.uuid)+'.'+str(self.index-1).zfill(4)
+        self.index_str = '.'+str(self.uuid)+'.'+str(self.index).zfill(4)
+        self.prev_index_str = '.'+str(self.uuid)+'.'+str(self.index-1).zfill(4)
         if self.is_node_group:
-            self.index_str=lambda : ''
-            self.prev_index_str=lambda : ''
+            self.index_str = ''
+            self.prev_index_str = ''
 
     def init_schema_links(self,):
         """ Sort and store the links to/from the Schema group node."""
@@ -151,7 +151,7 @@ class SchemaSolver:
     def gen_solve_iteration_mantis_nodes(self, frame_mantis_nodes, unprepared):
         for ui_node in self.tree.nodes:
             mantis_node_name = ui_node.name
-            index_str = self.index_str()
+            index_str = self.index_str
             mContext=self.node.mContext
             if isinstance(ui_node, SchemaUINode):
                 continue  # IGNORE the schema interface nodes, we already made them in __init__()
@@ -203,13 +203,13 @@ class SchemaSolver:
     def handle_link_from_index_input(self, index, frame_mantis_nodes, ui_link):
         from ..base_definitions import can_remove_socket_for_autogen
         _from_name, to_name = get_link_in_out(ui_link)
-        to_node = frame_mantis_nodes[ (*self.autogen_path_names, to_name+self.index_str()) ]
+        to_node = frame_mantis_nodes[ (*self.autogen_path_names, to_name+self.index_str) ]
 
         if (not can_remove_socket_for_autogen(to_node, ui_link.to_socket.name)) or \
                                     to_node.node_type in ['DUMMY', 'DUMMY_SCHEMA']:
             from .readtree import autogen_node
             unique_name = "".join([
-                ui_link.to_socket.node.name+self.index_str(),
+                ui_link.to_socket.node.name+self.index_str,
                 ui_link.from_socket.name, ui_link.from_socket.identifier,
                 "==>", ui_link.to_socket.name, ui_link.to_socket.identifier,],)
             signature = ("MANTIS_AUTOGENERATED", *self.tree_path_names[1:-1], unique_name)
@@ -232,7 +232,7 @@ class SchemaSolver:
         if to_name in replace_types:
             to_node = self.schema_nodes[(*self.autogen_path_names, to_name)]
         else:
-            to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str())]
+            to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str)]
         # this self.index_link is only used here?
         if self.index_link is None:
             # this should be impossible because the Schema gets an auto-generated Int input.
@@ -248,7 +248,7 @@ class SchemaSolver:
         if incoming is not None:
             from_node = incoming.from_node
             _from_name, to_name = get_link_in_out(ui_link)
-            to_node = frame_mantis_nodes[ (*self.autogen_path_names, to_name+self.index_str()) ]
+            to_node = frame_mantis_nodes[ (*self.autogen_path_names, to_name+self.index_str) ]
             socket_name=ui_link.to_socket.name
             if to_node.node_type in [ 'DUMMY_SCHEMA' ]:
                 socket_name=ui_link.to_socket.identifier
@@ -260,10 +260,10 @@ class SchemaSolver:
         for mantis_link in mantis_incoming_node.outputs[ui_link.to_socket.name].links:
             to_mantis_node, to_socket_name = mantis_link.to_node, mantis_link.to_socket
             from_name = get_link_in_out(ui_link)[0]
-            from_mantis_node = self.solved_nodes[ (*self.autogen_path_names, from_name+self.prev_index_str()) ]
+            from_mantis_node = self.solved_nodes[ (*self.autogen_path_names, from_name+self.prev_index_str) ]
 
             to_mantis_node_signature = ( *self.autogen_path_names,
-                            to_mantis_node.signature[-1] + self.index_str() )
+                            to_mantis_node.signature[-1] + self.index_str )
 
             # we need to detect if the next node is in a group.
             # REMEMBER: at this point, nested groups haven't been solved yet.
@@ -271,7 +271,7 @@ class SchemaSolver:
                     self.is_node_deeper_nested(to_mantis_node, from_mantis_node):
                 to_mantis_node = frame_mantis_nodes[ (
                     *self.autogen_path_names, # the SCHEMA_AUTOGENERATED string
-                    to_mantis_node.signature[-2]+ self.index_str() ) ]
+                    to_mantis_node.signature[-2]+ self.index_str ) ]
                 # this connection was forbidden before, right? so this should be a safe assumption.
                 assert to_mantis_node.node_type == 'DUMMY_SCHEMA', "I expected this to be a group/schema"
                 # we need to get the identifier of the named socket now.
@@ -300,7 +300,7 @@ class SchemaSolver:
             raise GraphError (f"{self.node} is missing a required input: {ui_link.from_socket.name}")
         from_node = incoming.from_node
         to_name = get_link_in_out(ui_link)[1]
-        to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str())]
+        to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str)]
         to_socket=ui_link.to_socket.name
         from ..base_definitions import MantisNodeGroup, SchemaGroup
         if isinstance(to_ui_node, (SchemaGroup, MantisNodeGroup)):
@@ -331,7 +331,7 @@ class SchemaSolver:
             raise RuntimeError(f"The array index {get_index} is out of bounds. Size: "
                                f"{len(self.array_input_connections[ui_link.from_socket.identifier])}")
         to_name = get_link_in_out(ui_link)[1]
-        to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str())]
+        to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str)]
         from_socket = incoming.from_node.outputs[incoming.from_socket]
         connection = from_socket.connect(to_node, ui_link.to_socket.name)
         # TODO: kill links  to the array get that are no longer needed
@@ -341,7 +341,7 @@ class SchemaSolver:
 
     def handle_link_to_array_input_get(self, frame_mantis_nodes, ui_link):
         from_name, to_name = get_link_in_out(ui_link)
-        from_mantis_node = frame_mantis_nodes[(*self.autogen_path_names, from_name+self.index_str())]
+        from_mantis_node = frame_mantis_nodes[(*self.autogen_path_names, from_name+self.index_str)]
         to_mantis_node = self.schema_nodes[(*self.tree_path_names, to_name)]
         # this only needs to be done once:
         if self.index == 0: # BUG? HACK? TODO find out what is going on here.
@@ -371,14 +371,14 @@ class SchemaSolver:
             else:
                 raise RuntimeError(wrapRed("make it so Mantis checks if there are enough Array inputs!"))
         to_name = get_link_in_out(ui_link)[1]
-        to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str())]
+        to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str)]
         connection = incoming.from_node.outputs[incoming.from_socket].connect(node=to_node, socket=ui_link.to_socket.name)
         init_connections(incoming.from_node)
 
     def handle_link_from_array_input_all(self, frame_mantis_nodes, ui_link):
         all_links = self.array_input_connections[ui_link.from_socket.identifier]
         to_name = get_link_in_out(ui_link)[1]
-        to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str())]
+        to_node = frame_mantis_nodes[(*self.autogen_path_names, to_name+self.index_str)]
         # connection = incoming.from_node.outputs[incoming.from_socket].connect(node=to_node, socket=ui_link.to_socket.name)
         for l in all_links:
             # we need to copy the link with the new from-node info
@@ -403,7 +403,7 @@ class SchemaSolver:
         from bpy.types import NodeSocket
         #use it directly if it is a mantis node; this happens when the previous node was a Schema
         if isinstance( ui_link.from_socket, NodeSocket): # normal
-            from_node = frame_mantis_nodes[(*self.autogen_path_names, from_name+self.index_str()) ]
+            from_node = frame_mantis_nodes[(*self.autogen_path_names, from_name+self.index_str) ]
         else: # it's a mantis socket, set manually while looping though prepped links
             from_node = ui_link.from_socket.node
         from_socket_name = ui_link.from_socket.name
@@ -425,7 +425,7 @@ class SchemaSolver:
         # wire the schema node itself to the output so it will push the connections when solving
         to_node = self.schema_nodes[(*self.tree_path_names, to_ui_node.bl_idname)]
         from_name = get_link_in_out(ui_link)[0]
-        from_node = frame_mantis_nodes[ (*self.autogen_path_names, from_name+self.index_str()) ]
+        from_node = frame_mantis_nodes[ (*self.autogen_path_names, from_name+self.index_str) ]
         connection = from_node.outputs[ui_link.from_socket.identifier].connect(node=to_node, socket=ui_link.to_socket.name)
 
     def handle_link_from_array_type_to_array_out(self, original_ui_link, dummy_link):
@@ -442,7 +442,7 @@ class SchemaSolver:
         from bpy.types import NodeSocket
         #use it directly if it is a mantis node; this happens when the previous node was a Schema
         if isinstance( ui_link.from_socket, NodeSocket): # normal
-            from_node = frame_mantis_nodes[(*self.autogen_path_names, from_name+self.index_str()) ]
+            from_node = frame_mantis_nodes[(*self.autogen_path_names, from_name+self.index_str) ]
         else: # it's a mantis socket, set manually while looping though prepped links
             from_node = ui_link.from_socket.node
         from_socket_name = ui_link.from_socket.name
@@ -452,7 +452,7 @@ class SchemaSolver:
             to_node = outgoing.to_node
             from ..schema_nodes import SchemaIndex
             if isinstance(from_node, SchemaIndex):
-                signature = ("MANTIS_AUTOGENERATED", *self.tree_path_names[1:-1], self.index_str(),
+                signature = ("MANTIS_AUTOGENERATED", *self.tree_path_names[1:-1], self.index_str,
                              ui_link.from_socket.name, ui_link.from_socket.identifier)
                 from_node = self.all_nodes.get(signature)
                 if not from_node:
@@ -646,8 +646,8 @@ class SchemaSolver:
 
             # for any of the special cases, we hit a 'continue' block. So this connection is not special, and is made here.
             connection = link_mantis_nodes(self.autogen_path_names, ui_link,
-                                frame_mantis_nodes, from_suffix=self.index_str(),
-                                to_suffix=self.index_str())
+                                frame_mantis_nodes, from_suffix=self.index_str,
+                                to_suffix=self.index_str)
 
         for signature, node in frame_mantis_nodes.items():
             self.solved_nodes[signature]=node
@@ -691,7 +691,7 @@ class SchemaSolver:
                 ui_link=self.spoof_link_for_subschema_to_output_edge_case(ui_link)
                 links_to_output[i] = ui_link
             from_name = get_link_in_out(ui_link)[0]
-            signature = (*self.autogen_path_names, from_name+self.index_str())
+            signature = (*self.autogen_path_names, from_name+self.index_str)
             #use it directly if it is a mantis node; this happens when the previous node was a Schema
             if hasattr(ui_link, "from_node") and (from_node := self.schema_nodes.get( (*self.node.ui_signature, ui_link.from_node.bl_idname))):
                 unprepared.append(from_node)
@@ -753,7 +753,7 @@ class SchemaSolver:
                     for outgoing in outgoing_links:
                         if outgoing:
                             to_node = outgoing.to_node
-                            from_node =mantis_nodes_in_frame[(*self.autogen_path_names, from_np.name+self.index_str()) ]
+                            from_node =mantis_nodes_in_frame[(*self.autogen_path_names, from_np.name+self.index_str) ]
                             from_socket_name = link.from_socket.name
                             if from_node.node_type in ['DUMMY_SCHEMA']:
                                 from_socket_name = link.from_socket.identifier
@@ -807,6 +807,7 @@ class SchemaSolver:
         for index in range(self.solve_length):
             self.index = index
             frame_mantis_nodes = self.solve_iteration()
+            self.set_index_strings()
             for sig, mantis_node in frame_mantis_nodes.items():
                 if mantis_node.node_type == 'DUMMY_SCHEMA':
                     self.nested_schemas[sig] = mantis_node