Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further Performance improvements #12

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

VincentKueszter
Copy link

Hello,

I sat down and tried to get a bit more performance out of the script.
Baseline, vertex colors only: 23,8 fps
I made the following changes, one per commit:

  • min/max clamping of weights per lambda: 24,08 fps (It's really hard to read imo, if this can be formatted in a better way, I'd be glad to improve it!)
  • vertex_color as 2D data structure -> easier to read and 25,21 fps (with only this change)
  • added global object for original edge length -> 25,8 fps (with only this change)
  • added index mapping: from the loop-based index to a vertex-based index, this also simplifies the setting of the vertex colors -> 28,37fps (with only this change)

I now get 31,32fps with all those changes together.

I'll mark this as draft for now, since I want to look into it a bit more, but your input would be appreciated!

@ScottishCyclops
Copy link
Owner

Thank you !
I'm about to read your code. That sounds promising.

tensionmap.py Outdated Show resolved Hide resolved
Copy link
Owner

@ScottishCyclops ScottishCyclops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really hard to read imo, if this can be formatted in a better way, I'd be glad to improve it!

I've always found the python way of writing inline ifs (ternary) very readable, as in you can read the line of code in English and it makes sense.

No problem with readability in my opinion.

I'm glad to hear this increases performance, because it clearly increases the overall readability too 👍

tensionmap.py Outdated Show resolved Hide resolved
tensionmap.py Outdated Show resolved Hide resolved
Copy link
Owner

@ScottishCyclops ScottishCyclops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, and a lot more readable again ! Good job.

tensionmap.py Outdated Show resolved Hide resolved
tensionmap.py Outdated Show resolved Hide resolved
tensionmap.py Outdated Show resolved Hide resolved
@VincentKueszter
Copy link
Author

It's really hard to read imo, if this can be formatted in a better way, I'd be glad to improve it!

I've always found the python way of writing inline ifs (ternary) very readable, as in you can read the line of code in English and it makes sense.

No problem with readability in my opinion.

I'm glad to hear this increases performance, because it clearly increases the overall readability too 👍

If I could, I would format it like this. It's a bit easier to see what happens in each case at a glance, in my opinion.

lower if value < lower else 
upper if value > upper else 
value

Copy link
Owner

@ScottishCyclops ScottishCyclops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like using a class for a single, may I say constant, variable.
I think the function (as it was in your previous commit) is better.

I'm the kind of dev that likes to use OOP only when it really makes sense, and keep to functions and data structures for the rest.

I don't think it resolves the problem of "If the object's geometry changes, you have to refresh manually", right ?

Here is what I propose:
This is an extra boost of real-time performance, for the ones that really need it. So why not use the same principle as the "cache" functionality found in many places in Blender ?
You would manually choose to "cache" a mesh for TensionMap, enabling this performance gain.
But since you manually chose to enable cache, then it's okay to have you update the cache when you change the mesh.

That way, most users have the current behaviour of auto updating every frame, but don't have the hassle of updating the mesh in TensionMap manually everytime.
And the hardcode real-time users can choose the functionality, knowing they will need to manually update.

If you don't want to work on the UI part of this, let me know, I'll gladly do it.
I'll take your current work here, turn it into a function, and link it to the UI.

Copy link
Owner

@ScottishCyclops ScottishCyclops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I like this.

But it would be under the same optional "cache" behaviour, because again, when you change your mesh, you would need to manually update the TensionMap. See my other comments.

@ScottishCyclops
Copy link
Owner

It's really hard to read imo, if this can be formatted in a better way, I'd be glad to improve it!

I've always found the python way of writing inline ifs (ternary) very readable, as in you can read the line of code in English and it makes sense.
No problem with readability in my opinion.
I'm glad to hear this increases performance, because it clearly increases the overall readability too +1

If I could, I would format it like this. It's a bit easier to see what happens in each case at a glance, in my opinion.

lower if value < lower else 
upper if value > upper else 
value

One line is fine by me. It starts to take more room than it really should otherwise.

@VincentKueszter
Copy link
Author

Here is what I propose:
This is an extra boost of real-time performance, for the ones that really need it. So why not use the same principle as the "cache" functionality found in many places in Blender ?
You would manually choose to "cache" a mesh for TensionMap, enabling this performance gain.
But since you manually chose to enable cache, then it's okay to have you update the cache when you change the mesh.
That way, most users have the current behaviour of auto updating every frame, but don't have the hassle of updating the mesh in TensionMap manually everytime.
And the hardcode real-time users can choose the functionality, knowing they will need to manually update.

Caching is a really fitting name for it! Sounds good.

If you don't want to work on the UI part of this, let me know, I'll gladly do it.
I'll take your current work here, turn it into a function, and link it to the UI.

I'll try it myself next week, the UI part didn't seem too complicated.

@ScottishCyclops
Copy link
Owner

I'll try it myself next week, the UI part didn't seem too complicated.

Alright.
I'm picturing a button that says "Cache Geometry Data" with a hover text of something like "Improve realtime performance by pre-calculating some geometry data. An update to the mesh will require a manual cache update".

When the cache is enabled, the button is replaced by two buttons (in the same line maybe) that say "Disable cache" and "Update Cache".

The update of the Cache would need to stop being linked with tm_update, because it would have it's own operator.

Have fun coding :)

@VincentKueszter
Copy link
Author

Okay, I re-implemented it as a cache.
I used dataclass instead of named tuple because it was a tiny bit faster.
I also updated the GUI and GUI code a bit, the row/col variable names were swapped and I removed some duplicated strings.
There should be no further performance improvements, even though I added a few more variables to avoid dot-chains.
Hope I didn't miss anything!

@VincentKueszter VincentKueszter marked this pull request as ready for review September 15, 2019 16:11
using BMesh for faster edge length calculation
made clamp use def, not assignment as per E731
fix: channel size set to 4, not 2
removed a variable when setting colors_tension_data for a minor performance boost
@VincentKueszter
Copy link
Author

VincentKueszter commented Sep 21, 2019

I added some more performance improvements by using bMesh:
7,9% more fps with vertex colors only and 10,2% with vertex groups only.

@ScottishCyclops
Copy link
Owner

Hey, Haven't had much time recently. I'll be sure to test & merge your changes as soon as I can. Thanks for the contributions !

@VincentKueszter
Copy link
Author

Hey, did you have time to look over it yet?

@ScottishCyclops
Copy link
Owner

Hey,
No sorry. Back to school and haven't had time.
This has gotten down in my priority list.

@VincentKueszter
Copy link
Author

Alright! I'll wait for a notification then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants