Regression: Inverting face selection now very slow #105046
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
6 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#105046
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?
System Information
Operating system: macOS-13.2.1-arm64-arm-64bit 64 Bits
Graphics card: Apple M1 Max Apple 4.1 Metal - 83
Blender Version
Broken: version: 3.4.1, branch: blender-v3.4-release, commit date: 2022-12-19 17:00, hash:
rB55485cb379f7
Worked: 3.3
Caused by
12becbf0df
Short description of error
Previously I was using Blender 3.3.1 and earlier. When I upgraded to 3.4.1 I found that inverting the selection on large meshes now takes a long time. Previously, on 3.3.1 it was almost instantaneous. This is noticeable on large meshes of around 1 million polys, but almost instant on smaller meshes with, say, 200K polys.
Exact steps for others to reproduce the error
Load up a mesh with at least 1 million polys. Select half the faces, and then Invert the selection. Instead of instantly changing the selection to the other faces, it sits there for several seconds thinking about it before it does it. This never happened with previous versions of Blender where it was pretty much instant.
I can also reproduce the drastic change in performance. I'll modify the main description for folks to re-create their own simple test case.
A quick profile shows the following:
It could be because of the ".select_edge" and ".select_poly" custom data layers on the mesh and the comment inside
um_arraystore_cd_compact
warning about dynamic layers.Can confirm
Inverting face selection now very slowto Regression: Inverting face selection now very slowCaused by
12becbf0df
@HooglyBoogly ^
Thanks for the investigation @deadpin. The dynamic layer thing seems to mean layers like vertex groups or multires masks/displacements, not simple boolean layers.
I find this whole "array store" thing to be pretty confusing. I'll run some testing though, the difference shouldn't be that dramatic.
Here's some timing information that may be useful for further investigation:
It looks like the "array store" system is quite slow for the boolean data that's changing. I don't know why it would take 4 entire seconds to compare 1 million booleans though, that sounds crazy.
I'm not familiar with the bmesh structure, but if its data is stored as small allocations in memory, and not an array, then the cache explains everything
@mod_moder Check out the code, it's
Mesh
that's being saved here, notBMesh
;)I'm having a hard time understanding the design decisions in the "array store" system. Many of the decisions seem to try to trade a large computational cost for decreases in memory usage when most data remains the same. That isn't the case here, and all of the processing ends up being pointless.
It also doesn't help that the system often processes each element individually. In this cases that's one byte at a time.
Here's a more in depth analysis of what the code is doing, in a test of a mesh with 1 million vertices.
BMesh
is converted to aMesh
. This uses the edit mesh -> original mesh conversion, so it doesn't use any of the recent performance improvements to that code. The process is entirely single-threaded.um_arraystore_compact_ex
, the undo mesh structure is converted into the "array store" format. The four attribute domains are processed sequentially, and each custom data layer is processed sequentially (no multithreading anywhere here).bchunk_list_from_data_merge
. This function allocates a 64 bit int for every element for a hash table. We've already used 8 times the memory as our original array.hash_array_from_data
hashes ALL bytes in the boolean array individually, single-threaded to fill the integer array.hash_accum
then adds up the entire array of 64 bit integers. 3 times!key_from_chunk_ref
then hashes all the data again, but this time in smaller chunks to make a table of accumulated hash values (the table size is 12000 hashes)table_lookup
is called. The table seems to be mostly empty. Though it looks like if it were to fill up that the behavior might become quadratic (over the size of the table).bchunk_list_append_data_n
, the data duplicated into small chunks of 248 bytes, which are added to a linked list. This is all in one thread.layer->data
is just freed in the end.@ideasman42, could you look into this bottleneck? It looks you're the original author of the array store system. To me it looks like it's working as intended here, but the amount of processing doesn't work well for boolean attributes when there are large changes in the data.
@HooglyBoogly I'll check on this, if it's simply the compacting the array that's slow, I'll check on optimizing this.