diff options
author | Hans Goudey <h.goudey@me.com> | 2021-12-22 17:52:46 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-12-22 17:52:46 +0300 |
commit | dbbf0e7f66524ac8c2d997e442d053f9f3c0590e (patch) | |
tree | dd5b0a246a697dfe4acc16d49a52c7639544f842 | |
parent | fdc4a1a590d8befb1ff9ab1de3f02d82aa46d539 (diff) |
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
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.cc | 3 |
2 files changed, 4 insertions, 2 deletions
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); } |