[Bf-blender-cvs] [54b293237ea] blender-v3.2-release: Fix T97375: changing node tree from Python is very slow

Jacques Lucke noreply at git.blender.org
Wed May 4 15:02:33 CEST 2022


Commit: 54b293237ea92f29aef05268836cab54c420d7ad
Author: Jacques Lucke
Date:   Wed May 4 15:02:19 2022 +0200
Branches: blender-v3.2-release
https://developer.blender.org/rB54b293237ea92f29aef05268836cab54c420d7ad

Fix T97375: changing node tree from Python is very slow

The issue was that the `NodeTreeRef` acceleration data structure was
rebuild much more often than necessary. That happened because the
Map Range node accidentally tagged the node tree for change even
though it did not actually change.

Differential Revision: https://developer.blender.org/D14842

===================================================================

M	source/blender/nodes/shader/nodes/node_shader_map_range.cc

===================================================================

diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc
index 9ba9a279c57..a487e07bd5a 100644
--- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc
@@ -66,24 +66,32 @@ static void node_shader_update_map_range(bNodeTree *ntree, bNode *node)
   const CustomDataType data_type = static_cast<CustomDataType>(storage.data_type);
   const int type = (data_type == CD_PROP_FLOAT) ? SOCK_FLOAT : SOCK_VECTOR;
 
-  LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
-    nodeSetSocketAvailability(ntree, socket, socket->type == type);
-  }
+  Array<bool> new_input_availability(BLI_listbase_count(&node->inputs));
+  Array<bool> new_output_availability(BLI_listbase_count(&node->outputs));
 
-  LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) {
-    nodeSetSocketAvailability(ntree, socket, socket->type == type);
+  int index;
+  LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &node->inputs, index) {
+    new_input_availability[index] = socket->type == type;
+  }
+  LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &node->outputs, index) {
+    new_output_availability[index] = socket->type == type;
   }
 
   if (storage.interpolation_type != NODE_MAP_RANGE_STEPPED) {
     if (type == SOCK_FLOAT) {
-      bNodeSocket *sockSteps = (bNodeSocket *)BLI_findlink(&node->inputs, 5);
-      nodeSetSocketAvailability(ntree, sockSteps, false);
+      new_input_availability[5] = false;
     }
     else {
-      bNodeSocket *sockSteps = (bNodeSocket *)BLI_findlink(&node->inputs, 11);
-      nodeSetSocketAvailability(ntree, sockSteps, false);
+      new_input_availability[11] = false;
     }
   }
+
+  LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &node->inputs, index) {
+    nodeSetSocketAvailability(ntree, socket, new_input_availability[index]);
+  }
+  LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &node->outputs, index) {
+    nodeSetSocketAvailability(ntree, socket, new_output_availability[index]);
+  }
 }
 
 static void node_shader_init_map_range(bNodeTree *UNUSED(ntree), bNode *node)



More information about the Bf-blender-cvs mailing list