[Bf-blender-cvs] [5b90c046d51] master: Fix: Object selection delay with many objects

RUben noreply at git.blender.org
Fri Jan 21 19:13:23 CET 2022


Commit: 5b90c046d519aa7723569c9bf4e6260126e44730
Author: RUben
Date:   Fri Jan 21 13:13:04 2022 -0500
Branches: master
https://developer.blender.org/rB5b90c046d519aa7723569c9bf4e6260126e44730

Fix: Object selection delay with many objects

With object collection properties open there was a huge delay when
switching active objects in a large scene, (~10k objects, ~5m vertices).
This is due to a non-optimal function to query all the collections the object is in.

To solve this the code can be simplified by using `bpy.types.Object.users_collection`
This returns all the collections the object is in removing the need to compute this in python.

===================================================================

M	release/scripts/startup/bl_ui/properties_object.py

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 81a641a20cf..fbd4ed3225a 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -184,24 +184,18 @@ class OBJECT_PT_collections(ObjectButtonsPanel, Panel):
             row.operator("object.collection_add", text="Add to Collection")
         row.operator("object.collection_add", text="", icon='ADD')
 
-        obj_name = obj.name
-        for collection in bpy.data.collections:
-            # XXX this is slow and stupid!, we need 2 checks, one that's fast
-            # and another that we can be sure its not a name collision
-            # from linked library data
-            collection_objects = collection.objects
-            if obj_name in collection.objects and obj in collection_objects[:]:
-                col = layout.column(align=True)
-
-                col.context_pointer_set("collection", collection)
-
-                row = col.box().row()
-                row.prop(collection, "name", text="")
-                row.operator("object.collection_remove", text="", icon='X', emboss=False)
-                row.menu("COLLECTION_MT_context_menu", icon='DOWNARROW_HLT', text="")
-
-                row = col.box().row()
-                row.prop(collection, "instance_offset", text="")
+        for collection in obj.users_collection:
+            col = layout.column(align=True)
+
+            col.context_pointer_set("collection", collection)
+
+            row = col.box().row()
+            row.prop(collection, "name", text="")
+            row.operator("object.collection_remove", text="", icon='X', emboss=False)
+            row.menu("COLLECTION_MT_context_menu", icon='DOWNARROW_HLT', text="")
+
+            row = col.box().row()
+            row.prop(collection, "instance_offset", text="")
 
 
 class OBJECT_PT_display(ObjectButtonsPanel, Panel):



More information about the Bf-blender-cvs mailing list