Skip to content

Reduce cost of joint lookups by reducing string allocations via use of std::string_view and heterogeneous map lookups #3970

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

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions indra/llappearance/llavatarappearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class LLAvatarAppearance : public LLCharacter
LLVector3 mHeadOffset{}; // current head position
LLAvatarJoint* mRoot{ nullptr };

typedef std::map<std::string, LLJoint*> joint_map_t;
typedef std::map<std::string, LLJoint*, std::less<>> joint_map_t;
joint_map_t mJointMap;

typedef std::map<std::string, LLVector3> joint_state_map_t;
Expand All @@ -151,7 +151,7 @@ class LLAvatarAppearance : public LLCharacter
public:
typedef std::vector<LLAvatarJoint*> avatar_joint_list_t;
const avatar_joint_list_t& getSkeleton() { return mSkeleton; }
typedef std::map<std::string, std::string> joint_alias_map_t;
typedef std::map<std::string, std::string, std::less<>> joint_alias_map_t;
const joint_alias_map_t& getJointAliases();


Expand Down
2 changes: 1 addition & 1 deletion indra/llcharacter/llbvhloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ LLQuaternion::Order bvhStringToOrder( char *str )
// LLBVHLoader()
//-----------------------------------------------------------------------------

LLBVHLoader::LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string>& joint_alias_map )
LLBVHLoader::LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string, std::less<>>& joint_alias_map )
{
reset();
errorLine = 0;
Expand Down
2 changes: 1 addition & 1 deletion indra/llcharacter/llbvhloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class LLBVHLoader
friend class LLKeyframeMotion;
public:
// Constructor
LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string>& joint_alias_map );
LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string, std::less<>>& joint_alias_map );
~LLBVHLoader();

/*
Expand Down
7 changes: 3 additions & 4 deletions indra/llcharacter/llcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ LLCharacter::~LLCharacter()
//-----------------------------------------------------------------------------
// getJoint()
//-----------------------------------------------------------------------------
LLJoint *LLCharacter::getJoint( const std::string &name )
LLJoint* LLCharacter::getJoint(std::string_view name)
{
LLJoint* joint = NULL;
LLJoint* joint = nullptr;

LLJoint *root = getRootJoint();
if (root)
if (LLJoint* root = getRootJoint())
{
joint = root->findJoint(name);
}
Expand Down
2 changes: 1 addition & 1 deletion indra/llcharacter/llcharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class LLCharacter
// get the specified joint
// default implementation does recursive search,
// subclasses may optimize/cache results.
virtual LLJoint *getJoint( const std::string &name );
virtual LLJoint* getJoint(std::string_view name);

// get the position of the character
virtual LLVector3 getCharacterPosition() = 0;
Expand Down
7 changes: 3 additions & 4 deletions indra/llcharacter/lljoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,20 @@ LLJoint *LLJoint::getRoot()
//-----------------------------------------------------------------------------
// findJoint()
//-----------------------------------------------------------------------------
LLJoint *LLJoint::findJoint( const std::string &name )
LLJoint* LLJoint::findJoint(std::string_view name)
{
if (name == getName())
return this;

for (LLJoint* joint : mChildren)
{
LLJoint *found = joint->findJoint(name);
if (found)
if (LLJoint* found = joint->findJoint(name))
{
return found;
}
}

return NULL;
return nullptr;
}


Expand Down
2 changes: 1 addition & 1 deletion indra/llcharacter/lljoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class LLJoint
LLJoint *getRoot();

// search for child joints by name
LLJoint *findJoint( const std::string &name );
LLJoint* findJoint(std::string_view name);

// add/remove children
void addChild( LLJoint *joint );
Expand Down
2 changes: 1 addition & 1 deletion indra/llprimitive/lldaeloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ LLDAELoader::LLDAELoader(
void* opaque_userdata,
JointTransformMap& jointTransformMap,
JointNameSet& jointsFromNodes,
std::map<std::string, std::string>& jointAliasMap,
std::map<std::string, std::string, std::less<>>& jointAliasMap,
U32 maxJointsPerMesh,
U32 modelLimit,
bool preprocess)
Expand Down
26 changes: 13 additions & 13 deletions indra/llprimitive/lldaeloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ class LLDAELoader : public LLModelLoader
dae_model_map mModelsMap;

LLDAELoader(
std::string filename,
S32 lod,
LLModelLoader::load_callback_t load_cb,
LLModelLoader::joint_lookup_func_t joint_lookup_func,
LLModelLoader::texture_load_func_t texture_load_func,
LLModelLoader::state_callback_t state_cb,
void* opaque_userdata,
JointTransformMap& jointTransformMap,
JointNameSet& jointsFromNodes,
std::map<std::string, std::string>& jointAliasMap,
U32 maxJointsPerMesh,
U32 modelLimit,
bool preprocess);
std::string filename,
S32 lod,
LLModelLoader::load_callback_t load_cb,
LLModelLoader::joint_lookup_func_t joint_lookup_func,
LLModelLoader::texture_load_func_t texture_load_func,
LLModelLoader::state_callback_t state_cb,
void* opaque_userdata,
JointTransformMap& jointTransformMap,
JointNameSet& jointsFromNodes,
std::map<std::string, std::string, std::less<>>& jointAliasMap,
U32 maxJointsPerMesh,
U32 modelLimit,
bool preprocess);
virtual ~LLDAELoader() ;

virtual bool OpenFile(const std::string& filename);
Expand Down
26 changes: 13 additions & 13 deletions indra/llprimitive/llgltfloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ static const std::string lod_suffix[LLModel::NUM_LODS] =
};


LLGLTFLoader::LLGLTFLoader(std::string filename,
S32 lod,
LLModelLoader::load_callback_t load_cb,
LLModelLoader::joint_lookup_func_t joint_lookup_func,
LLModelLoader::texture_load_func_t texture_load_func,
LLModelLoader::state_callback_t state_cb,
void * opaque_userdata,
JointTransformMap & jointTransformMap,
JointNameSet & jointsFromNodes,
std::map<std::string, std::string> &jointAliasMap,
U32 maxJointsPerMesh,
U32 modelLimit) //,
//bool preprocess)
LLGLTFLoader::LLGLTFLoader(std::string filename,
S32 lod,
LLModelLoader::load_callback_t load_cb,
LLModelLoader::joint_lookup_func_t joint_lookup_func,
LLModelLoader::texture_load_func_t texture_load_func,
LLModelLoader::state_callback_t state_cb,
void * opaque_userdata,
JointTransformMap & jointTransformMap,
JointNameSet & jointsFromNodes,
std::map<std::string, std::string, std::less<>> & jointAliasMap,
U32 maxJointsPerMesh,
U32 modelLimit) //,
//bool preprocess)
: LLModelLoader( filename,
lod,
load_cb,
Expand Down
24 changes: 12 additions & 12 deletions indra/llprimitive/llgltfloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ class LLGLTFLoader : public LLModelLoader
typedef std::map<std::string, LLImportMaterial> material_map;

LLGLTFLoader(std::string filename,
S32 lod,
LLModelLoader::load_callback_t load_cb,
LLModelLoader::joint_lookup_func_t joint_lookup_func,
LLModelLoader::texture_load_func_t texture_load_func,
LLModelLoader::state_callback_t state_cb,
void * opaque_userdata,
JointTransformMap & jointTransformMap,
JointNameSet & jointsFromNodes,
std::map<std::string, std::string> &jointAliasMap,
U32 maxJointsPerMesh,
U32 modelLimit); //,
//bool preprocess );
S32 lod,
LLModelLoader::load_callback_t load_cb,
LLModelLoader::joint_lookup_func_t joint_lookup_func,
LLModelLoader::texture_load_func_t texture_load_func,
LLModelLoader::state_callback_t state_cb,
void * opaque_userdata,
JointTransformMap & jointTransformMap,
JointNameSet & jointsFromNodes,
std::map<std::string, std::string,std::less<>> &jointAliasMap,
U32 maxJointsPerMesh,
U32 modelLimit); //,
//bool preprocess );
virtual ~LLGLTFLoader();

virtual bool OpenFile(const std::string &filename);
Expand Down
2 changes: 1 addition & 1 deletion indra/llprimitive/llmodelloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LLJoint;

typedef std::map<std::string, LLMatrix4> JointTransformMap;
typedef std::map<std::string, LLMatrix4>::iterator JointTransformMapIt;
typedef std::map<std::string, std::string> JointMap;
typedef std::map<std::string, std::string, std::less<>> JointMap;
typedef std::deque<std::string> JointNameSet;

const S32 SLM_SUPPORTED_VERSION = 3;
Expand Down
4 changes: 2 additions & 2 deletions indra/newview/llfloaterbvhpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void LLFloaterBvhPreview::setAnimCallbacks()
getChild<LLUICtrl>("ease_out_time")->setValidateBeforeCommit( boost::bind(&LLFloaterBvhPreview::validateEaseOut, this, _1));
}

std::map <std::string, std::string> LLFloaterBvhPreview::getJointAliases()
std::map<std::string, std::string, std::less<>> LLFloaterBvhPreview::getJointAliases()
{
LLPointer<LLVOAvatar> av = (LLVOAvatar*)mAnimPreview->getDummyAvatar();
return av->getJointAliases();
Expand Down Expand Up @@ -252,7 +252,7 @@ bool LLFloaterBvhPreview::postBuild()
ELoadStatus load_status = E_ST_OK;
S32 line_number = 0;

std::map<std::string, std::string> joint_alias_map = getJointAliases();
auto joint_alias_map = getJointAliases();

loaderp = new LLBVHLoader(file_buffer, load_status, line_number, joint_alias_map);
std::string status = getString(STATUS[load_status]);
Expand Down
2 changes: 1 addition & 1 deletion indra/newview/llfloaterbvhpreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class LLFloaterBvhPreview : public LLFloaterNameDesc
S32 status, LLExtStat ext_status);
private:
void setAnimCallbacks() ;
std::map <std::string, std::string> getJointAliases();
std::map<std::string, std::string, std::less<>> getJointAliases();


protected:
Expand Down
2 changes: 1 addition & 1 deletion indra/newview/llfloatermodelpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ void LLFloaterModelPreview::updateAvatarTab(bool highlight_overrides)
{
// Populate table

std::map<std::string, std::string> joint_alias_map;
std::map<std::string, std::string, std::less<>> joint_alias_map;
mModelPreview->getJointAliases(joint_alias_map);

S32 conflicts = 0;
Expand Down
2 changes: 1 addition & 1 deletion indra/newview/llmodelpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ void LLModelPreview::loadModel(std::string filename, S32 lod, bool force_disable

mLODFile[lod] = filename;

std::map<std::string, std::string> joint_alias_map;
std::map<std::string, std::string, std::less<>> joint_alias_map;
getJointAliases(joint_alias_map);

LLHandle<LLModelPreview> preview_handle = getHandle();
Expand Down
8 changes: 4 additions & 4 deletions indra/newview/llvoavatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6306,13 +6306,13 @@ const LLUUID& LLVOAvatar::getID() const
// getJoint()
//-----------------------------------------------------------------------------
// RN: avatar joints are multi-rooted to include screen-based attachments
LLJoint *LLVOAvatar::getJoint( const std::string &name )
LLJoint* LLVOAvatar::getJoint(std::string_view name)
{
joint_map_t::iterator iter = mJointMap.find(name);

LLJoint* jointp = NULL;
LLJoint* jointp = nullptr;

if (iter == mJointMap.end() || iter->second == NULL)
if (iter == mJointMap.end() || iter->second == nullptr)
{ //search for joint and cache found joint in lookup table
if (mJointAliasMap.empty())
{
Expand All @@ -6329,7 +6329,7 @@ LLJoint *LLVOAvatar::getJoint( const std::string &name )
canonical_name = name;
}
jointp = mRoot->findJoint(canonical_name);
mJointMap[name] = jointp;
mJointMap[std::string(name)] = jointp;
}
else
{ //return cached pointer
Expand Down
2 changes: 1 addition & 1 deletion indra/newview/llvoavatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class LLVOAvatar :
void startDefaultMotions();
void dumpAnimationState();

virtual LLJoint* getJoint(const std::string &name);
virtual LLJoint* getJoint(std::string_view name);
LLJoint* getJoint(S32 num);

//if you KNOW joint_num is a valid animated joint index, use getSkeletonJoint for efficiency
Expand Down
6 changes: 3 additions & 3 deletions indra/newview/llvoavatarself.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,17 +695,17 @@ void LLVOAvatarSelf::idleUpdate(LLAgent &agent, const F64 &time)
}

// virtual
LLJoint *LLVOAvatarSelf::getJoint(const std::string &name)
LLJoint* LLVOAvatarSelf::getJoint(std::string_view name)
{
std::lock_guard lock(mJointMapMutex);
LLJoint *jointp = NULL;
LLJoint* jointp = nullptr;
jointp = LLVOAvatar::getJoint(name);
if (!jointp && mScreenp)
{
jointp = mScreenp->findJoint(name);
if (jointp)
{
mJointMap[name] = jointp;
mJointMap[std::string(name)] = jointp;
}
}
if (jointp && jointp != mScreenp && jointp != mRoot)
Expand Down
2 changes: 1 addition & 1 deletion indra/newview/llvoavatarself.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class LLVOAvatarSelf :
/*virtual*/ bool hasMotionFromSource(const LLUUID& source_id);
/*virtual*/ void stopMotionFromSource(const LLUUID& source_id);
/*virtual*/ void requestStopMotion(LLMotion* motion);
/*virtual*/ LLJoint* getJoint(const std::string &name);
/*virtual*/ LLJoint* getJoint(std::string_view name);

/*virtual*/ void renderJoints();

Expand Down
Loading