From 131404a1bdde40ce8c9080edd4c060c983767a25 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 25 Aug 2025 17:18:01 +0200 Subject: [PATCH] Nodes: optimize socket usage inferencing for many group inputs This was found to be a bottleneck in the file from #144756 which has 235 group inputs and 174 group input nodes, which leads to 40,890 sockets. Most of those are never used, so it's wasteful to add them to the map of input values. The inferencing time improved from 24ms to 16ms. Can likely still be improved more, but that's a good improvement for such a small change already. --- source/blender/nodes/intern/socket_usage_inference.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/blender/nodes/intern/socket_usage_inference.cc b/source/blender/nodes/intern/socket_usage_inference.cc index 0e12c5d2966..7002598afc3 100644 --- a/source/blender/nodes/intern/socket_usage_inference.cc +++ b/source/blender/nodes/intern/socket_usage_inference.cc @@ -85,6 +85,12 @@ struct SocketUsageInferencer { for (const bNode *node : root_tree_.group_input_nodes()) { for (const int i : root_tree_.interface_inputs().index_range()) { const bNodeSocket &socket = node->output_socket(i); + if (!socket.is_directly_linked()) { + /* This socket is not linked, hence it's value is never used. Thus we don't have to add + * it to #all_socket_values_. This optimization helps a lot when the node group has a + * very large number of inputs and group input nodes. */ + continue; + } const SocketInContext socket_in_context{nullptr, &socket}; const void *input_value = nullptr; if (!this->treat_socket_as_unknown(socket_in_context)) {