From 29aaa2922d1ddca50116aa7434a34d89b41b98e7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 22 Jan 2024 12:27:55 +0100 Subject: [PATCH] Fix performance issue when tagging relations for update The relations update code does tagging needed to ensure that the array of bases is updated when relations are updated. It was done by tagging the Scene ID node, and potentially recursing into all dependent depsgraph nodes. If there is a driver on a scene property it was unnecessarily re-evaluated. This solves the slow behavior of adding objects in the test file from #117335. Pull Request: https://projects.blender.org/blender/blender/pulls/117403 --- .../depsgraph/intern/depsgraph_build.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc index 8da3f80a223..822fe1e5f81 100644 --- a/source/blender/depsgraph/intern/depsgraph_build.cc +++ b/source/blender/depsgraph/intern/depsgraph_build.cc @@ -281,15 +281,19 @@ void DEG_graph_tag_relations_update(Depsgraph *graph) DEG_DEBUG_PRINTF(graph, TAG, "%s: Tagging relations for update.\n", __func__); deg::Depsgraph *deg_graph = reinterpret_cast(graph); deg_graph->need_update_relations = true; - /* NOTE: When relations are updated, it's quite possible that - * we've got new bases in the scene. This means, we need to - * re-create flat array of bases in view layer. - * - * TODO(sergey): Try to make it so we don't flush updates - * to the whole depsgraph. */ + + /* NOTE: When relations are updated, it's quite possible that we've got new bases in the scene. + * This means, we need to re-create flat array of bases in view layer. */ + /* TODO(sergey): It is expected that bases manipulation tags scene for update to tag bases array + * for re-creation. Once it is ensured to happen from all places this implicit tag can be + * removed. */ deg::IDNode *id_node = deg_graph->find_id_node(°_graph->scene->id); if (id_node != nullptr) { - id_node->tag_update(deg_graph, deg::DEG_UPDATE_SOURCE_RELATIONS); + graph_id_tag_update(deg_graph->bmain, + deg_graph, + °_graph->scene->id, + ID_RECALC_BASE_FLAGS, + deg::DEG_UPDATE_SOURCE_RELATIONS); } }