This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
Maya: Improve lib.polyConstraint performance when Select tool is not the active tool context #2447
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
The Maya validators Validate Mesh Non Zero Edge and Validate Mesh NGONs rely on using Maya's poly selection constraints to quickly retrieve the relevant components. However, since these rely on Maya selection of actual vertices/edges there are UI edges cases that can make this query very slow for high-res meshes.
The issue is basically that it is extremely slow when the user is NOT currently in the Select tool context. As if other manipulators do some extra processing during this step that introduces a huge performance drop. Previously it could literally take MINUTES for a very a bunch of very high res meshes to be processed.
This PR implements an optimization by ensuring the tool context is currently set to the the Select tool and not e.g. the Translate, Rotate, Scale or other tools since those produce the extreme slow down. I've seen performance increasements of over 100x speed difference. With this change I've not seen these validations take much longer than a second at most - and those were the most extreme cases - where previously they literally could take minutes.
With this speed optimization it makes these validators actually useful as opposed to "in the way".
Performance tests
With four cubes at 300x300x300 subdivs with Translate tool active:
With four cubes at 300x300x300 subdivs with Select tool active. This is the case that didn't have speed issues before:
Click to expand for script used to test performance difference.
Note
The speed comparison can be a bit tricky since running the same query multiple times within the same code block might execute faster on the separate run. For example, have a look at this time difference when running the Old first and then the New version. And running the code with the New first and the Old version after.
It seems that if the newer version runs first that even the old one isn't as slow as it was. As if somehow the resulting value is "cached" already in memory and thus gives less issue with Manipulators being visible.
Nevertheless, the new code basically always performs optimally with just a minor decrease in speed for the case where it previously didn't encounter the speed issue so this should be a no brainer.
Also the speed difference seems to be much less in Maya 2022 (maybe the manipulators are optimized?) but still quite present.
Related
I originally posted about this a long time ago in the OpenPype discord. Here's a link to that.