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

Optimize Sdf_PathNode::GetPathToken() by avoiding unnecessary memory allocation #3312

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pxr/usd/sdf/pathNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ namespace {
// nullptr property node pointer) plus all the properties that hang off it.
struct _PropToTokenTable
{
void Init() {
_data = std::make_shared<_Data>();
}

// Note that this function returns a TfToken lvalue reference that needs to
// live/be valid as long as this object is around.
template <class Fn>
Expand Down Expand Up @@ -471,7 +475,7 @@ struct _PropToTokenTable
tbb::spin_mutex mutex;
};

std::shared_ptr<_Data> _data { new _Data };
std::shared_ptr<_Data> _data;
};

} // anon
Expand All @@ -494,9 +498,12 @@ Sdf_PathNode::GetPathToken(Sdf_PathNode const *primPart,
TfAutoMallocTag tag2("Sdf_PathNode::GetPathToken");

_PrimToPropTokenTables::accessor primAccessor;
_pathTokenTable->insert(
bool newValue = _pathTokenTable->insert(
primAccessor, std::make_pair(primPart, _PropToTokenTable()));
auto &propToTokenTable = primAccessor->second;
if (newValue) {
propToTokenTable.Init();
}
// Release the primAccessor here, since the call to _CreatePathToken below
// can cause reentry here (for embedded target paths).
primAccessor.release();
Expand Down