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

MAYA-110878 - handle multiple deferred notifs for single path #1519

Conversation

seando-adsk
Copy link
Collaborator

MAYA-110878 - MayaUSD sends some UFE attribute changed notifications for attributes which don't exist, and drops some notifications

  • Handle multiple deferred notifications for a single path (keeping the original notif order).

…for attributes which don't exist, and drops some notifications

* Handle multiple deferred notifications for a single path
  (keeping the original notif order).
@seando-adsk seando-adsk added bug Something isn't working ufe-usd Related to UFE-USD plugin in Maya-Usd labels Jun 23, 2021
// 1) Order of notifs must be maintained.
// 2) Allow notif with same path, but different token. At worst the check is linear
// in the size of the vector (which is the same as an unordered_multimap).
std::vector<std::pair<Ufe::Path, TfToken>> pendingAttributeChangedNotifications;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Change is pretty simple. I just changed the container to vector (for reasons give here). I ran all the UFE tests and they all passed with no test changes required. I believe this is due to the previous changes around line 420 which ignore inert prim changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that vector will not be fast enough for the duplicate notification elimination at line 95. While the worst case is the same, the average case or unordered_map is constant while the average case the vector is linear in the size of the vector.

I think to do better you can have a second container which is a std::unordered_set< std::pair<Ufe::Path, TfToken> >. The idea is you use the set to test if the std::pair<Ufe::Path, TfToken> has already been saved in the vector in constant time, and you use the vector to maintain ordering. We trade off a little constant time & some space, but we avoid the linear search.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do see your point, but I wonder if its really needed. I added some tf_debug statements to print out when a notif gets delayed. I ran all the "UFE" tests and the largest size the pendingAttributeChangedNotifications vector got was only 2. Granted the tests aren't real-world data, but I think that when normally running the notif guard will expire and send the pending notifs long before they ever have a chance to build up. @ppt-adsk What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hard to say, I tend to think @seando-adsk you're right, but it's a code complexity vs. performance guarantee tradeoff. Can we perhaps put up a message if the vector size grows above some threshold?

Copy link
Contributor

Choose a reason for hiding this comment

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

The case I'm worried about is someone writing a script that iterates over everything in the scene and changes each one a little bit, say changing the purpose of each rprim. That is going to create N messages and have O(N^2) complexity because it is doing a linear search.

If you really don't like the unordered_set we can leave it as-is and ask QA to play around with some heavy scenes and see if they hit any performance issues.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you look here you can see where we use the notif guard - basically when setting a single usd attribute. In your scenario on each prim we change a little bit we will enter/leave a notif guard. So I don't ever see this notif guard growing beyond just a few notifs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay sounds good to me!

sendValueChanged(ufePath, changedPath.GetNameToken());
}
#endif
UFE_V2(valueChanged(ufePath, changedPath.GetNameToken());)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Use the helper func which checks the notif guard. The previous code would also not add this value changed to the deferred notifs if we were in a guard.

// 1) Order of notifs must be maintained.
// 2) Allow notif with same path, but different token. At worst the check is linear
// in the size of the vector (which is the same as an unordered_multimap).
std::vector<std::pair<Ufe::Path, TfToken>> pendingAttributeChangedNotifications;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that vector will not be fast enough for the duplicate notification elimination at line 95. While the worst case is the same, the average case or unordered_map is constant while the average case the vector is linear in the size of the vector.

I think to do better you can have a second container which is a std::unordered_set< std::pair<Ufe::Path, TfToken> >. The idea is you use the set to test if the std::pair<Ufe::Path, TfToken> has already been saved in the vector in constant time, and you use the vector to maintain ordering. We trade off a little constant time & some space, but we avoid the linear search.

@seando-adsk seando-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Jun 30, 2021
@kxl-adsk kxl-adsk merged commit f8a72dc into dev Jun 30, 2021
@kxl-adsk kxl-adsk deleted the donnels/MAYA-110878/handle_multiple_pending_notification_for_path branch June 30, 2021 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready-for-merge Development process is finished, PR is ready for merge ufe-usd Related to UFE-USD plugin in Maya-Usd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants