From 52cff75ce08092a2f9a4ba46899bbf097988f618 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 11 Apr 2024 17:26:08 -0400 Subject: [PATCH] Geometry Nodes: Avoid repeated node tools lookup when empty Currently the node tools asset tree for extending 3D view headers is rebuilt whenever it's cleared, which is done by clearing the tree's storage. That means the data is rebuilt on every redraw if there are no node tools and the tree storage is empty. With larger asset libraries that can be quite expensive. Now, instead of clearing the map, use a new dirty tag to store whether the asset tree is out of date compared to the assets. This should resolve #120494 --- source/blender/editors/asset/ED_asset_filter.hh | 2 ++ source/blender/editors/asset/intern/asset_filter.cc | 3 ++- source/blender/editors/geometry/node_group_operator.cc | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/asset/ED_asset_filter.hh b/source/blender/editors/asset/ED_asset_filter.hh index 889a51f69da..9f1770ea17f 100644 --- a/source/blender/editors/asset/ED_asset_filter.hh +++ b/source/blender/editors/asset/ED_asset_filter.hh @@ -54,6 +54,8 @@ struct AssetItemTree { assets_per_path; /** Assets not added to a catalog, not part of #assets_per_path. */ Vector unassigned_assets; + /** True if the tree is out of date compared to asset libraries and must be rebuilt. */ + bool dirty = true; }; asset_system::AssetCatalogTree build_filtered_catalog_tree( diff --git a/source/blender/editors/asset/intern/asset_filter.cc b/source/blender/editors/asset/intern/asset_filter.cc index 92450986c80..02d9c9a1816 100644 --- a/source/blender/editors/asset/intern/asset_filter.cc +++ b/source/blender/editors/asset/intern/asset_filter.cc @@ -150,7 +150,8 @@ AssetItemTree build_filtered_all_catalog_tree( return {std::move(catalogs_with_node_assets), std::move(assets_per_path), - std::move(unassigned_assets)}; + std::move(unassigned_assets), + false}; } } // namespace blender::ed::asset diff --git a/source/blender/editors/geometry/node_group_operator.cc b/source/blender/editors/geometry/node_group_operator.cc index d5f15adb170..b39d0622cda 100644 --- a/source/blender/editors/geometry/node_group_operator.cc +++ b/source/blender/editors/geometry/node_group_operator.cc @@ -787,7 +787,7 @@ void clear_operator_asset_trees() for (const ObjectType type : {OB_MESH, OB_CURVES, OB_POINTCLOUD}) { for (const eObjectMode mode : {OB_MODE_OBJECT, OB_MODE_EDIT, OB_MODE_SCULPT_CURVES}) { if (asset::AssetItemTree *tree = get_static_item_tree(type, mode)) { - *tree = {}; + tree->dirty = true; } } } @@ -1105,7 +1105,7 @@ void ui_template_node_operator_asset_root_items(uiLayout &layout, const bContext if (!tree) { return; } - if (tree->assets_per_path.size() == 0) { + if (tree->dirty) { *tree = build_catalog_tree(C, *active_object); }