Mesh: speedup BKE_mesh_validate #121413

Merged
Aras Pranckevicius merged 6 commits from aras_p/blender:mesh_validate_perf into main 2024-05-07 12:29:43 +02:00

BKE_mesh_validate is called by mesh.validate() Python API, as well as optionally when doing file imports. This PR speeds it up a bit:

  • Faster face data sorting by using parallel sort instead of qsort,
  • One allocation for all face vertex indices, instead of a separate allocation for each face,
  • (more like a fix) Validation no longer adds a MDeformVert layer when there was none in the input mesh.
  • Small cleanups (more const inputs, etc.)

On my Windows/VS2022/Ryzen5950X machine, import time in seconds:

Data set Validation on, main Validation on, this PR Validation off
USD (Intel Moore Lane) 9.1 6.7 4.8
OBJ (Blender 3.0 splash) 22.7 18.6 16.5
`BKE_mesh_validate` is called by `mesh.validate()` Python API, as well as optionally when doing file imports. This PR speeds it up a bit: - Faster face data sorting by using parallel sort instead of qsort, - One allocation for all face vertex indices, instead of a separate allocation for each face, - (more like a fix) Validation no longer adds a MDeformVert layer when there was none in the input mesh. - Small cleanups (more const inputs, etc.) On my Windows/VS2022/Ryzen5950X machine, import time in seconds: |Data set |Validation on, main |Validation on, this PR |Validation off | |-----------|------------|------------|-----------| |USD (Intel Moore Lane) | 9.1 | 6.7 | 4.8 | |OBJ (Blender 3.0 splash) | 22.7 | 18.6 | 16.5 |
Aras Pranckevicius added 5 commits 2024-05-03 21:44:59 +02:00
Among the several sorts that BKE_mesh_validate does, looks like most
of the time is spent in the qsort comparison function call overhead.
Use std::sort instead, which can avoid that, as well as potentially
use a better sorting algorithm than qsort.

Windows/VS2022, import times with mesh validate on:
- USD, Intel Moore Lane: 9.1->7.8s (no validation 4.8s)
- OBJ, blender 3 splash: 22.7->20.3s (no validation 16.5s)
- Const input when possible,
- BitVector instead of BLI_bitmap,
- Array instead of manual memory alloc
Instead of allocating one array for each SortFace, allocate one large
array for all of them, and make SortFaces just point to it.

Windows/VS2022, import times with mesh validate on:
- USD, Intel Moore Lane: 7.8->7.4s (no validation 4.8s)
- OBJ, blender 3 splash: 20.3->19.8s (no validation 16.5s)
Make the three face sorting loops use parallel_sort.

Windows/VS2022, import times with mesh validate on:
- USD, Intel Moore Lane: 7.4->6.7s (no validation 4.8s)
- OBJ, blender 3 splash: 19.8->18.6s (no validation 16.5s)
Mesh: mesh validation no longer adds MDeformVert layer when there wasn't one
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
7fa3bffe68
This saves only a tiny amount of time, but is a nice thing to not modify
the meshes without a good reason.
Author
Member

@blender-bot build

@blender-bot build
Aras Pranckevicius requested review from Hans Goudey 2024-05-03 22:10:13 +02:00
Hans Goudey approved these changes 2024-05-07 00:39:34 +02:00
Hans Goudey left a comment
Member

The changes look pretty clear. Thanks!

The changes look pretty clear. Thanks!
@ -443,6 +443,9 @@ bool BKE_mesh_runtime_is_valid(Mesh *mesh_eval)
do_fixes,
&changed);
MDeformVert *dverts = CustomData_has_layer(&mesh_eval->vert_data, CD_MDEFORMVERT) ?
Member

This is equivalent to static_cast<MDeformVert *>(CustomData_get_layer_for_write(&mesh_eval->vert_data, CD_MDEFORMVERT, mesh_eval->verts_num))

This is equivalent to `static_cast<MDeformVert *>(CustomData_get_layer_for_write(&mesh_eval->vert_data, CD_MDEFORMVERT, mesh_eval->verts_num))`
aras_p marked this conversation as resolved
Aras Pranckevicius added 1 commit 2024-05-07 12:27:35 +02:00
Aras Pranckevicius merged commit 6efa5c16ab into main 2024-05-07 12:29:43 +02:00
Aras Pranckevicius deleted branch mesh_validate_perf 2024-05-07 12:29:46 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
2 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#121413
No description provided.