Commit: dbbf0e7f66524ac8c2d997e442d053f9f3c0590e Author: Hans Goudey Date: Wed Dec 22 08:52:46 2021 -0600 Branches: master https://developer.blender.org/rBdbbf0e7f66524ac8c2d997e442d053f9f3c0590e
Nodes: Improve node tree copy performance When copying a full node tree, we can avoid an O(n^2) loop finding a unique name for every node if we assume they already have unique names. That is a reasonable assumption, since unique names are verified elsewhere when adding a new node. Copying a node tree with about 4000 nodes took 42 ms before, now it takes 6 ms. Differential Revision: https://developer.blender.org/D13644 =================================================================== M source/blender/blenkernel/BKE_node.h M source/blender/blenkernel/intern/node.cc =================================================================== diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 1e0a75bfc57..7fbf9de53ce 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -702,7 +702,8 @@ namespace blender::bke { /** * \note keeps socket list order identical, for copying links. - * \note `unique_name` needs to be true. It's only disabled for speed when doing GPUnodetrees. + * \note `unique_name` should usually be true, unless the \a dst_tree is temporary, + * or the names can already be assumed valid. */ bNode *node_copy_with_mapping(bNodeTree *dst_tree, const bNode &node_src, diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 05096ae63c1..e5aa28f8e0a 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -158,8 +158,9 @@ static void ntree_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c BLI_listbase_clear(&ntree_dst->nodes); LISTBASE_FOREACH (const bNode *, src_node, &ntree_src->nodes) { + /* Don't find a unique name for every node, since they should have valid names already. */ bNode *new_node = blender::bke::node_copy_with_mapping( - ntree_dst, *src_node, flag_subdata, true, socket_map); + ntree_dst, *src_node, flag_subdata, false, socket_map); node_map.add(src_node, new_node); } _______________________________________________ Bf-blender-cvs mailing list [email protected] List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
