removing orphan meshes is slow (after they were in use) #118787
Labels
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118787
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Blender 4.0.2
Was working on a script that were creating some temporary meshes (used temporary meshes to keep original geometry still available and easy to switch back) but what I've noticed is the bottle neck in that workflow is not actually processing thousands of meshes geometry using bmesh but just removing left out mesh data.
At first I thought that removing meshes is slow in general but what I've found that removing orphan meshes that were just created and never used goes very fast but if meshes were assigned to some object and then unassigned then removing them becomes 10x slower.
Example script is below, it can be executed in default Blender session - it has two methods that both print timings in console:
Was wondering if it's a known problem or it is a bug.
Also noticed that orphan meshes were not removed during 2nd method (you accomplish that also by setting
skip_removal
toTrue
at the end of the script) and then removed manually from UI usingbpy.ops.outliner.id_operation(type="DELETE")
it works a bit faster. There is also option to run "purge all" in Orphan Data outliner and it's lightning fast but it doesn't allow removing specific meshes.The problem here is likely
bpy.data.meshes.remove(mesh)
because its default arguments result inbpy.data.meshes.remove(mesh, do_unlink=True, do_id_user=True, do_ui_user=True)
, which presumably checks all 6500 Objects for being users ofmesh
on each call (plus UI and more).In this script's case, it's known that number of users of the mesh will be zero, so the mesh can be deleted with
bpy.data.meshes.remove(mesh, do_unlink=False, do_id_user=False, do_ui_user=False)
If the number of users is accurate,
bpy.data.meshes.remove()
could probably be updated check the number of users first and then skip the extra work when the number of users is zero. The following does the check manually:For removal of multiple IDs at once, there is also
bpy.data.batch_remove(iterable)
, though note that it is considered experimental and less safe:mesh.users == 0
as above@Mysteryem, thank you for the detailed explanation and the suggested solution to improve the performance of @Andrej730 's script.
It will certainly be helpful for anyone encountering similar issues ;)
@Andrej730, while we appreciate your effort in optimizing performance, potential performance improvements are not handled as bug reports. We continuously work on enhancing Blender's performance, but such optimizations are typically addressed through coding best practices and workflow enhancements.
So closing this report as it pertains to a potential performance improvement.
Thank you for workaround. Settings
do_unlink
toFalse
indeed speeds things up. Didn't know aboutbpy.data.batch_remove
- it should even work with different types of IDs.Didn't planned this as a performance issue report - just thought that removing meshes from same conditions but with very decreased performance may indicate some deeper issue.