Page MenuHome

Weld modifier: Decrease memory usage
Changes PlannedPublic

Authored by Germano Cavalcante (mano-wii) on Dec 18 2021, 11:28 PM.

Details

Summary

Often the context is just 2 vertices, so it's not worth allocating large arrays to create the Weld context.

Resize the arrays in the end so that memory is better used in other areas.

Diff Detail

Repository
rB Blender
Branch
arcpatch-D13622 (branched from master)
Build Status
Buildable 19529
Build 19529: arc lint + arc unit

Event Timeline

Germano Cavalcante (mano-wii) requested review of this revision.Dec 18 2021, 11:28 PM
Germano Cavalcante (mano-wii) created this revision.
  • Cleanup: Use Vector initializer to set size
Germano Cavalcante (mano-wii) planned changes to this revision.Dec 18 2021, 11:47 PM

I suspect that resize is not decreasing memory usage...

source/blender/modifiers/intern/MOD_weld.cc
379

Wouldn't it be possible to calculate the size of this exactly, depending on the vert_kill_len and the original number of vertices?
Then it wouldn't even need to be a vector.

  • Copy the resized Array
source/blender/modifiers/intern/MOD_weld.cc
379

Unfortunately not.
vert_kill_len only indicates how many vertices are going to be killed, but they can be welded to each other or with different vertices.
The number of vertices in the context can vary. (I think between vert_kill_len + 1 and 2 * vert_kill_len).

I am not familiar with this code, but if you are looking at reducing memory, have you tried switching to pre-increment instead of post-increment, to make sure you aren’t making a copy and destroying it every loop, in the cases that the compiler is unable to optimize away?

I am not familiar with this code, but if you are looking at reducing memory, have you tried switching to pre-increment instead of post-increment, to make sure you aren’t making a copy and destroying it every loop, in the cases that the compiler is unable to optimize away?

I'm not sure what you mean. I need an example.

++i vs i++ and possibly ++wvert_len vs wvert_len++ for example. Take the suggestion with a large grain of salt, as I just found out about post increment creating a copy of the value before increasing the value and returning the copy, and I don’t fully grasp where preincrement isn’t applicable.

Sources:
https://google.github.io/styleguide/cppguide.html#Preincrement_and_Predecrement

https://herbsutter.com/2013/05/13/gotw-2-solution-temporary-objects/
The section titled “The iterator increment uses postincrement.”

Germano Cavalcante (mano-wii) planned changes to this revision.Dec 20 2021, 4:31 PM

No benefits shown in performance tests. (between 1% and 2% penalty)