Anim: thread remake_graph_transdata #119497

Merged
Christoph Lendenfeld merged 13 commits from ChrisLend/blender:thread_remake_transdata into main 2024-04-09 11:46:17 +02:00

On animations with high key counts, remake_graph_transdata takes most of the compute time when moving keys.
This patch threads the loop over FCurves in that function to speed things up.

Test file with 10.000 keys per F-Curve

- Before After
Moving 1 key of each FCurve ~2200ms ~285ms
Moving a single key ~0.70ms ~0.72ms

As demonstrated in the measurements, this speeds up the case of modifying a lot of data, while not impacting the case of modifying very little data.
The measurements were taken on an 8c/16t CPU. The higher the thread count, the better the performance gain.

Measurements of remake_graph_transdata using the following test file.
https://download.blender.org/ftp/sybren/animation-rigging/heavy_mocap_test.blend


For the review:

  • Is it needed to exclude testhandles_fcurve from the threading? Is it an issue if we create threads within threads?
    Answer by @HooglyBoogly on Blender Chat: No, that's done all the time, and it's a great way to achieve more parallelism. It's a good way to cover both 10000 different FCurves with 4 points each, and 4 FCurves with 10000 points each in the same code
    Doing this gave an additional speedup (grain size 1) from 330ms to 275ms.

Grain Size Tests
Note: those tests were done before moving testhandles_fcurve into the threaded loop

Grain Size Time
1 ~330ms
4 ~334ms
16 ~338ms
64 ~ 355ms
256 ~865ms
1024 ~1630ms
On animations with high key counts, `remake_graph_transdata` takes most of the compute time when moving keys. This patch threads the loop over FCurves in that function to speed things up. Test file with 10.000 keys per F-Curve | - | Before | After | | - | - | - | | Moving 1 key of each FCurve | ~2200ms | ~285ms | | Moving a single key | ~0.70ms | ~0.72ms | As demonstrated in the measurements, this speeds up the case of modifying a lot of data, while not impacting the case of modifying very little data. The measurements were taken on an 8c/16t CPU. The higher the thread count, the better the performance gain. Measurements of `remake_graph_transdata` using the following test file. https://download.blender.org/ftp/sybren/animation-rigging/heavy_mocap_test.blend ------ For the review: * ~~Is it needed to exclude `testhandles_fcurve` from the threading? Is it an issue if we create threads within threads?~~ Answer by @HooglyBoogly on Blender Chat: `No, that's done all the time, and it's a great way to achieve more parallelism. It's a good way to cover both 10000 different FCurves with 4 points each, and 4 FCurves with 10000 points each in the same code` Doing this gave an additional speedup (grain size 1) from 330ms to 275ms. **Grain Size Tests** Note: those tests were done before moving `testhandles_fcurve` into the threaded loop | Grain Size | Time | | - | - | | 1 | ~330ms | | 4 | ~334ms | | 16 | ~338ms | | 64 | ~ 355ms | | 256 | ~865ms | | 1024 | ~1630ms |
Christoph Lendenfeld added the
Module
Animation & Rigging
label 2024-03-15 10:20:13 +01:00
Christoph Lendenfeld added 1 commit 2024-03-15 10:20:25 +01:00
Christoph Lendenfeld added 2 commits 2024-03-21 11:54:04 +01:00
Christoph Lendenfeld added 1 commit 2024-03-21 12:02:21 +01:00
Christoph Lendenfeld added 1 commit 2024-03-26 10:03:46 +01:00
Christoph Lendenfeld added 1 commit 2024-03-26 10:19:04 +01:00
Christoph Lendenfeld requested review from Sybren A. Stüvel 2024-03-28 14:53:58 +01:00
Christoph Lendenfeld requested review from Hans Goudey 2024-03-28 14:54:05 +01:00
Falk David reviewed 2024-03-28 14:59:40 +01:00
@ -893,3 +893,1 @@
for (FCurve *fcu : fcurves) {
if (fcu->bezt) {
BeztMap *bezm;
blender::threading::parallel_for(fcurves.index_range(), 1, [&](const blender::IndexRange range) {
Member

Looks like you don't need the index here, so it might be better to use parallel_for_each. Of course, that's only if you actually want a grain size of one.

Looks like you don't need the index here, so it might be better to use `parallel_for_each`. Of course, that's only if you actually want a grain size of one.

Even with grain size 1, range can have any size. But i wonder if this will be better to test parallel_for_weighted here.

Even with grain size `1`, `range` can have any size. But i wonder if this will be better to test `parallel_for_weighted` here.
Member

parallel_for_each uses a different algorithm internally that has more overhead. AFAIK it will always give each element its own thread. I think it's typically only suitable for much more expensive tasks.

`parallel_for_each` uses a different algorithm internally that has more overhead. AFAIK it will always give each element its own thread. I think it's typically only suitable for much more expensive tasks.
dr.sybren marked this conversation as resolved
Christoph Lendenfeld added 2 commits 2024-03-28 15:31:33 +01:00
Christoph Lendenfeld added 1 commit 2024-03-28 15:35:03 +01:00
Hans Goudey approved these changes 2024-03-28 16:07:47 +01:00
Hans Goudey left a comment
Member

How about a grain size of 8?

How about a grain size of 8?
Christoph Lendenfeld added 2 commits 2024-04-02 10:18:14 +02:00
Sybren A. Stüvel approved these changes 2024-04-09 11:26:53 +02:00
Sybren A. Stüvel left a comment
Member

Nice work! Just two small notes that can be addressed when landing.

Nice work! Just two small notes that can be addressed when landing.
@ -893,3 +892,1 @@
for (FCurve *fcu : fcurves) {
if (fcu->bezt) {
BeztMap *bezm;
blender::threading::parallel_for(fcurves.index_range(), 8, [&](const blender::IndexRange range) {

Add a comment that explains how the 8 got here.

Add a comment that explains how the 8 got here.
@ -899,3 +896,1 @@
bezm = bezt_to_beztmaps(fcu->bezt, fcu->totvert);
sort_time_beztmaps(bezm, fcu->totvert);
beztmap_to_data(t, fcu, bezm, fcu->totvert);
if (fcu->bezt) {

if (!fcu->bezt) { continue; }

Gitea already doesn't present this as "it's all the same, just indented", so I think it's fine to restructure the code a bit further for readability.

`if (!fcu->bezt) { continue; }` Gitea already doesn't present this as "it's all the same, just indented", so I think it's fine to restructure the code a bit further for readability.
Christoph Lendenfeld added 2 commits 2024-04-09 11:42:37 +02:00
Christoph Lendenfeld merged commit 8a79212031 into main 2024-04-09 11:46:17 +02:00
Christoph Lendenfeld deleted branch thread_remake_transdata 2024-04-09 11:46:19 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser Project (Legacy)
Interest
Asset System
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
5 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#119497
No description provided.