Poor redo panel performance when using a big asset library #120494

Closed
opened 2024-04-10 23:48:50 +02:00 by passivestar · 12 comments

System Information
Operating system: macOS-14.4-arm64-arm-64bit 64 Bits
Graphics card: Metal API Apple M1 Max 1.2

Blender Version
Broken: version: 4.1.1 Release Candidate, branch: blender-v4.1-release, commit date: 2024-04-09 15:11, hash: 917159affcf8
Was also broken in 4.0 and 4.1
Worked: 3.6

Short description of error
When using an asset library with a lot of assets in it (over 15k meshes and materials in total) it becomes noticably slow to change values in the redo panel, see a video here

Exact steps for others to reproduce the error
Since I can't really share my 50GB asset library here I don't know how to make it easy to reproduce, but I suppose one could try creating a blend file with 20000 suzannes in it and mark those as assets? It's possible that the asset library gets refreshed on redo or something like that (the asset library panel doesn't need to be opened for this bug to happen)

**System Information** Operating system: macOS-14.4-arm64-arm-64bit 64 Bits Graphics card: Metal API Apple M1 Max 1.2 **Blender Version** Broken: version: 4.1.1 Release Candidate, branch: blender-v4.1-release, commit date: 2024-04-09 15:11, hash: `917159affcf8` Was also broken in 4.0 and 4.1 Worked: 3.6 **Short description of error** When using an asset library with a lot of assets in it (over 15k meshes and materials in total) it becomes noticably slow to change values in the redo panel, [see a video here](https://twitter.com/passivestar_/status/1738547801653428582) **Exact steps for others to reproduce the error** Since I can't really share my 50GB asset library here I don't know how to make it easy to reproduce, but I suppose one could try creating a blend file with 20000 suzannes in it and mark those as assets? It's possible that the asset library gets refreshed on redo or something like that (the asset library panel doesn't need to be opened for this bug to happen)
passivestar added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2024-04-10 23:48:51 +02:00
Member

Thanks for the report. A few clarification questions:

  1. What sort of storage is your asset library on? Hard drive, ssd?
  2. How many separate files does the library consist of?
  3. Anything special about the asset preview images?
Thanks for the report. A few clarification questions: 1. What sort of storage is your asset library on? Hard drive, ssd? 2. How many separate files does the library consist of? 3. Anything special about the asset preview images?
Member

Hi, thanks for the report. Thought this was fixed already with #115372. Maybe not entirely resolved yet.

Hi, thanks for the report. Thought this was fixed already with #115372. Maybe not entirely resolved yet.
Pratik Borhade added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2024-04-11 05:02:08 +02:00
Author

Thanks for the report. A few clarification questions:

  1. What sort of storage is your asset library on? Hard drive, ssd?
  2. How many separate files does the library consist of?
  3. Anything special about the asset preview images?
  1. ssd, macbook's built-in
  2. 48 blend files
  3. not that I'm aware of, they seem to load just fine. they're all autogenerated
> Thanks for the report. A few clarification questions: > 1. What sort of storage is your asset library on? Hard drive, ssd? > 2. How many separate files does the library consist of? > 3. Anything special about the asset preview images? 1. ssd, macbook's built-in 2. 48 blend files 3. not that I'm aware of, they seem to load just fine. they're all autogenerated
Pratik Borhade added
Status
Needs Triage
and removed
Status
Needs Information from User
labels 2024-04-11 06:51:23 +02:00
Member

Since this is a bit tricky to set up, I quickly hacked together a python and bash script to make this a bit easier.

  1. Set up a folder that's part of the Preferences > File Paths > Asset Libraries. E.g. /home/test_library/ named Test Library.
  2. In this folder, create a create_assets.py and a script.sh file.
  3. Copy the content from below into the scripts.
  4. Set up the blender_exec e.g. path/to/blender and change the number of files and number of asset you want to create. 500 assets take around 15 seconds to create on my mashine, so that's around 12.5 minutes to run it for 50 blend files.
  5. Run it with bash script.sh to create the whole test asset library.

create_assets.py:

import bpy
import sys
argv = sys.argv[sys.argv.index("--") + 1:]

file_name = argv[0]
num_assets = int(argv[1])

bpy.ops.mesh.primitive_monkey_add(enter_editmode=False)
base_ob_suzanne = bpy.context.active_object

view_layer = bpy.context.view_layer

for i in range(num_assets):
    name = f"TestAsset{file_name}_{i}"
    copy_object = bpy.data.objects.new(name=name, object_data=base_ob_suzanne.data.copy())
    copy_object.asset_mark()
    copy_object.asset_generate_preview()
    view_layer.active_layer_collection.collection.objects.link(copy_object)

bpy.ops.wm.save_mainfile(filepath=f"{file_name}.blend", check_existing=False, exit=True)

script.sh:

#!/bin/bash

blender_exec="blender"
num_files=50
num_assets_per_file=500

for i in $(seq $num_files); do
  file_name="test_asset_file_$i"
  echo "Creating $file_name.blend"
  $blender_exec --background --python create_assets.py -- $file_name $num_assets_per_file
  echo "Done"
done
Since this is a bit tricky to set up, I quickly hacked together a python and bash script to make this a bit easier. 1. Set up a folder that's part of the `Preferences` > `File Paths` > `Asset Libraries`. E.g. `/home/test_library/` named `Test Library`. 2. In this folder, create a `create_assets.py` and a `script.sh` file. 3. Copy the content from below into the scripts. 4. Set up the `blender_exec` e.g. `path/to/blender` and change the number of files and number of asset you want to create. 500 assets take around 15 seconds to create on my mashine, so that's around 12.5 minutes to run it for 50 blend files. 5. Run it with `bash script.sh` to create the whole test asset library. `create_assets.py`: ```py import bpy import sys argv = sys.argv[sys.argv.index("--") + 1:] file_name = argv[0] num_assets = int(argv[1]) bpy.ops.mesh.primitive_monkey_add(enter_editmode=False) base_ob_suzanne = bpy.context.active_object view_layer = bpy.context.view_layer for i in range(num_assets): name = f"TestAsset{file_name}_{i}" copy_object = bpy.data.objects.new(name=name, object_data=base_ob_suzanne.data.copy()) copy_object.asset_mark() copy_object.asset_generate_preview() view_layer.active_layer_collection.collection.objects.link(copy_object) bpy.ops.wm.save_mainfile(filepath=f"{file_name}.blend", check_existing=False, exit=True) ``` `script.sh`: ```sh #!/bin/bash blender_exec="blender" num_files=50 num_assets_per_file=500 for i in $(seq $num_files); do file_name="test_asset_file_$i" echo "Creating $file_name.blend" $blender_exec --background --python create_assets.py -- $file_name $num_assets_per_file echo "Done" done ```
Member

With a 2.5 GB asset library, I can't notice any slowdowns in the viewport, but I can see blender spending a lot of time in ed::geometry::ui_template_node_operator_asset_root_items (14% of samples) @HooglyBoogly :
image

Steps to reproduce:

  1. Set up the asset library as described above.
  2. Open Blender with the General template.
  3. Enter edit mode on the Cube, select the top face and extrude it.
  4. Use the sliders in the redo panel to constantly redo the operator
With a 2.5 GB asset library, I can't notice any slowdowns in the viewport, but I can see blender spending a lot of time in `ed::geometry::ui_template_node_operator_asset_root_items` (14% of samples) @HooglyBoogly : ![image](/attachments/acd4b73a-40c0-4967-836a-620946ff5d44) Steps to reproduce: 1. Set up the asset library as described above. 2. Open Blender with the `General` template. 3. Enter edit mode on the `Cube`, select the top face and extrude it. 4. Use the sliders in the redo panel to constantly redo the operator
186 KiB
Member

Didn't get a chance to test yet, but I'm guessing the problem is that it's trying to search for node tools because it didn't find any. The solution probably looks like this:

diff --git a/source/blender/editors/asset/ED_asset_filter.hh b/source/blender/editors/asset/ED_asset_filter.hh
index 889a51f69da..b9566e1ee1f 100644
--- a/source/blender/editors/asset/ED_asset_filter.hh
+++ b/source/blender/editors/asset/ED_asset_filter.hh
@@ -54,6 +54,7 @@ struct AssetItemTree {
       assets_per_path;
   /** Assets not added to a catalog, not part of #assets_per_path. */
   Vector<asset_system::AssetRepresentation *> unassigned_assets;
+  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);
   }

Either way though, the stuff in that profile is probably worth optimizing, since asset libraries will only continue to grow in the future. In particular it's absurd how much time is spent checking if a file is hidden.

Didn't get a chance to test yet, but I'm guessing the problem is that it's trying to search for node tools because it didn't find any. The solution probably looks like this: ```diff diff --git a/source/blender/editors/asset/ED_asset_filter.hh b/source/blender/editors/asset/ED_asset_filter.hh index 889a51f69da..b9566e1ee1f 100644 --- a/source/blender/editors/asset/ED_asset_filter.hh +++ b/source/blender/editors/asset/ED_asset_filter.hh @@ -54,6 +54,7 @@ struct AssetItemTree { assets_per_path; /** Assets not added to a catalog, not part of #assets_per_path. */ Vector<asset_system::AssetRepresentation *> unassigned_assets; + 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); } ``` Either way though, the stuff in that profile is probably worth optimizing, since asset libraries will only continue to grow in the future. In particular it's absurd how much time is spent checking if a file is hidden.

Is this something that could be backported to the upcoming Blender 4.1.1 as well...?

Is this something that could be backported to the upcoming Blender 4.1.1 as well...?

I'll look at the cost of is_hidden_dot_filename function itself.

I'll look at the cost of `is_hidden_dot_filename` function itself.
Blender Bot added
Status
Resolved
and removed
Status
Needs Triage
labels 2024-04-11 23:27:31 +02:00
Member

I didn't mean for 52cff75ce0 to automatically close this, but I'm pretty confident that will be the solution so I'll leave it like that for now. @passivestar, could you test the next daily build to check if it fixes the issue for you? If so, the commit is simple and can be backported to 4.1.

Optimizing this is still worth it anyway, because this data still has to be calculated when Blender starts.

I didn't mean for 52cff75ce08092a2f9a4ba46899bbf097988f618 to automatically close this, but I'm pretty confident that will be the solution so I'll leave it like that for now. @passivestar, could you test the next daily build to check if it fixes the issue for you? If so, the commit is simple and can be backported to 4.1. Optimizing this is still worth it anyway, because this data still has to be calculated when Blender starts.
Author

@passivestar, could you test the next daily build to check if it fixes the issue for you?

will do 👍

> @passivestar, could you test the next daily build to check if it fixes the issue for you? will do 👍
Author

Works well in the latest 4.2 build, thanks for the fix 🎉 🙌

Works well in the latest 4.2 build, thanks for the fix 🎉 🙌
Member

Committed 19dbcf5fc1 which should significantly improve the speed of AssetList::iterate() for large asset libraries in this case and similar ones. See #120699 for benchmarks.

Committed 19dbcf5fc1 which should significantly improve the speed of `AssetList::iterate()` for large asset libraries in this case and similar ones. See #120699 for benchmarks.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
7 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#120494
No description provided.