Page MenuHome

Fix T78296: Performance - Use Binary Search for MDeformWeight
Changes PlannedPublic

Authored by Jeroen Bakker (jbakker) on Jun 26 2020, 12:23 PM.

Details

Summary

Use binary search for querying deform weights.

Spring 02_020_A.anim.blend on Ryzen 1700X goes from 12.4 to 12.7fps.

During profiling it was detected that adding new items to the head was faster than adding to the tail.

Diff Detail

Repository
rB Blender
Branch
T78296-mdeformweight-binsearch (branched from master)
Build Status
Buildable 8720
Build 8720: arc lint + arc unit

Event Timeline

Jeroen Bakker (jbakker) requested review of this revision.Jun 26 2020, 12:23 PM
Jeroen Bakker (jbakker) created this revision.

Removed unneeded whiteline

This is not a finished implementation, right?
I believe there are multiple other places, where def_nr is changed, which would destroy the sorting.

source/blender/blenkernel/intern/deform.c
724

dvert->dw may be null.
qsort does not explicity allow this, even if most implementations do.

734

I'd prefer array indexing.

829

This shifts the array, right?
Shouldn't it be memmove then?

Jeroen Bakker (jbakker) planned changes to this revision.Jun 26 2020, 3:00 PM
Jeroen Bakker (jbakker) marked 3 inline comments as done.

Ah yes your right ->def_nr = gives some more results.

source/blender/blenkernel/intern/deform.c
734

Seems MSVC is able to generate the correct code for this as well so will do your preferred way.

Jeroen Bakker (jbakker) marked an inline comment as done.Jun 26 2020, 3:00 PM
Jeroen Bakker (jbakker) planned changes to this revision.Jun 26 2020, 3:04 PM
Harbormaster completed remote builds in B8728: Diff 26309.
Jeroen Bakker (jbakker) retitled this revision from Fix T78296: MDeformWeight performance to Fix T78296: Performance - Use Binary Search for MDeformWeight.Jun 29 2020, 9:14 AM

add sorting to places that changed def_nr directly

Sync with master, use subversion bump

Generally looks good.

  • We should assert when the groups aren't sorted - see: P1520.
  • There are a some places I think sorting may still be needed. layerInterp_mdeformvert, BKE_object_defgroup_index_map_apply, if sorting isn't needed for either of these - there should be an explanation of why since it's not obvious.
  • We could make BKE_mesh_validate sort the groups, not urgent though.
  • The comment above MDeformWeight.def_nr in the header should note that this is expected to be sorted.
  • There could be a fast-path for adding a single group to an existing, sorted array.
This revision is now accepted and ready to land.Jul 10 2020, 10:16 AM

Comments from code review

  • We should assert when the groups aren't sorted
  • Added sorting to layerInterp_mdeformvert, BKE_object_defgroup_index_map_apply they change def_nr and should be sorted again.
  • Added comment of sorting in DNA.
This revision is now accepted and ready to land.Jul 10 2020, 6:11 PM
source/blender/blenkernel/intern/deform.c
673

Let's say totweight == 1
Then high == 0, and therefore low < high is false.
So this would make it return -1, whenever a vertex has only one group?

829

Missing parentheses?

Jeroen Bakker (jbakker) planned changes to this revision.Jul 14 2020, 5:45 PM

Needs more testing and development