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

Minimize name-based lookup of proxy shape nodes. #1245

Merged
merged 5 commits into from
Mar 19, 2021

Conversation

ppt-adsk
Copy link
Collaborator

The UsdStageMap was performing name-based lookup of proxy shape nodes on every access. This has been replaced with a scheme that uses an unordered map index by Ufe::Path, which are hashable.

#include <cassert>

PXR_NAMESPACE_USING_DIRECTIVE

namespace {

MObjectHandle proxyShapeHandle(const Ufe::Path& path)
MObjectHandle nameLookup(const Ufe::Path& path)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed function name to make it very clear what's involved.

@@ -68,15 +98,10 @@ UsdStageMap g_StageMap;
// UsdStageMap
//------------------------------------------------------------------------------

void UsdStageMap::addItem(const Ufe::Path& path, UsdStageWeakPtr stage)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No need to pass in the stage, you can simply retrieve it from the proxy shape when populating the cache.

UsdStageWeakPtr UsdStageMap::stage(const Ufe::Path& path)
UsdStageWeakPtr UsdStageMap::stage(const Ufe::Path& path) { return objToStage(proxyShape(path)); }

MObject UsdStageMap::proxyShape(const Ufe::Path& path)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the engine method for the stage() and proxyShapeNode() methods. It indexes into the unordered map of MObjectHandle's to proxy shapes using the Ufe::Path hash. This is how we avoid name-based lookups.

return iter == std::end(fPathToObject) ? MObject() : iter->second.object();
}

MayaUsdProxyShapeBase* UsdStageMap::proxyShapeNode(const Ufe::Path& path)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New accessor to the cache for the proxy shape node pointer. Allows us to retrieve data from the proxy shape node, such as time, or enabled purposes.

auto stage = ProxyShapeHandler::dagPathToStage(psn);
addItem(ufePath, stage);
for (const auto& psn : ProxyShapeHandler::getAllNames()) {
addItem(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rebuilding is now simpler, name-based lookup now done by addItem.

nothing in the data model prevents it). To generalized access to the
underlying node, we store an MObjectHandle in the maps.

The cache is refreshed on access to a stage given a path which cannot be
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Still wish to avoid having the cache observe the data model, to avoid observation cost as well as order of notification problems. Rebuild on access failure is simpler to code, and access failure through incorrect input is most likely not a high-frequency code path.

proxyShapeObj = proxyShapeDagPath.node();
cache = std::pair<Ufe::Path, MObjectHandle>(proxyShapePath, MObjectHandle(proxyShapeObj));
// Proxy shape node should not be null.
auto proxyShape = g_StageMap.proxyShapeNode(path);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed homebrew, single node caching in favor of using the global proxy shape cache.

@kxl-adsk kxl-adsk added the ufe-usd Related to UFE-USD plugin in Maya-Usd label Mar 11, 2021
@ppt-adsk ppt-adsk added ready-for-merge Development process is finished, PR is ready for merge do-not-merge-yet Development is not finished, PR not ready for merge and removed ready-for-merge Development process is finished, PR is ready for merge labels Mar 16, 2021
@ppt-adsk
Copy link
Collaborator Author

Will have QA try this branch out quickly before we merge.

@ppt-adsk
Copy link
Collaborator Author

David Santos tested this branch manually, and ran QATA tests, so good to go.

@ppt-adsk ppt-adsk added ready-for-merge Development process is finished, PR is ready for merge and removed do-not-merge-yet Development is not finished, PR not ready for merge labels Mar 19, 2021
@kxl-adsk kxl-adsk merged commit df49777 into dev Mar 19, 2021
@kxl-adsk kxl-adsk deleted the tremblp/MAYA-102616/nameToDagPathRemoval branch March 19, 2021 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants