From 5bb57186350fe00ccdc3f28acc3a55861745e193 Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Mon, 8 Oct 2018 16:16:56 +0100
Subject: [PATCH] SL-9805 - optimization for avatar rigging info updates

---
 indra/newview/llvoavatar.cpp | 33 ++++++++++++++++++++++++---------
 indra/newview/llvoavatar.h   |  4 +++-
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index b49f22007b..85019d5ae0 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -1418,14 +1418,7 @@ void LLVOAvatar::calculateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
     // Stretch bounding box by rigged mesh joint boxes
     if (box_detail>=3)
     {
-        // FIXME could try to cache unless something has changed about attached rigged meshes, 
-        // but needs more logic based on volume states.
-
-        //if (mRiggingInfoTab.needsUpdate())
-        {
-            updateRiggingInfo();
-            //mJointRiggingInfoTab.setNeedsUpdate(false);
-        }
+		updateRiggingInfo();
         for (S32 joint_num = 0; joint_num < LL_CHARACTER_MAX_ANIMATED_JOINTS; joint_num++)
         {
             LLJoint *joint = getJoint(joint_num);
@@ -9624,9 +9617,31 @@ void LLVOAvatar::getAssociatedVolumes(std::vector<LLVOVolume*>& volumes)
 void LLVOAvatar::updateRiggingInfo()
 {
     LL_DEBUGS("RigSpammish") << getFullname() << " updating rig tab" << LL_ENDL;
-    mJointRiggingInfoTab.clear();
     std::vector<LLVOVolume*> volumes;
     getAssociatedVolumes(volumes);
+
+	// Get current rigging info key
+	std::map<LLUUID,S32> curr_rigging_info_key;
+    for (std::vector<LLVOVolume*>::iterator it = volumes.begin(); it != volumes.end(); ++it)
+    {
+        LLVOVolume *vol = *it;
+		if (vol->isMesh() && vol->getVolume())
+		{
+			const LLUUID& mesh_id = vol->getVolume()->getParams().getSculptID();
+			S32 max_lod = llmax(vol->getLOD(), vol->mLastRiggingInfoLOD);
+			curr_rigging_info_key[mesh_id] = max_lod;
+		}
+	}
+
+	// Check for key change, which indicates some change in volume composition or LOD.
+	if (curr_rigging_info_key == mLastRiggingInfoKey)
+	{
+		return;
+	}
+
+	// Something changed. Update.
+	mLastRiggingInfoKey = curr_rigging_info_key;
+    mJointRiggingInfoTab.clear();
     for (std::vector<LLVOVolume*>::iterator it = volumes.begin(); it != volumes.end(); ++it)
     {
         LLVOVolume *vol = *it;
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 985559f2d6..e6b1477758 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -220,7 +220,9 @@ public:
 
     // virtual
     void 					updateRiggingInfo();
-
+	// This encodes mesh id and LOD, so we can see whether display is up-to-date.
+	std::map<LLUUID,S32>	mLastRiggingInfoKey;
+	
     std::set<LLUUID>		mActiveOverrideMeshes;
     virtual void			onActiveOverrideMeshesChanged();
     
-- 
GitLab