Cool VL Viewer forum

View unanswered posts | View active topics It is currently 2024-03-28 08:40:35



Reply to topic  [ 5 posts ] 
Try a boost::container::flat_map for faster lookup 
Author Message

Joined: 2011-10-07 10:39:20
Posts: 181
Reply with quote
Trying to speed up the joint_map_t cache.
Looks beneficial in the profiler.

Code:
--- linden_orig/indra/llappearance/llavatarappearance.h   Thu Jul  9 21:40:56 2020
+++ linden/indra/llappearance/llavatarappearance.h   Thu Oct  8 02:18:03 2020
@@ -32,10 +32,11 @@
 
 #ifndef LL_AVATAR_APPEARANCE_H
 #define LL_AVATAR_APPEARANCE_H
 
 #include <vector>
+#include <boost/container/flat_map.hpp>
 
 #include "llavatarappearancedefines.h"
 #include "llavatarjointmesh.h"
 #include "llcharacter.h"
 #include "lldriverparam.h"
@@ -152,11 +153,11 @@
 
 public:
    LLVector3            mHeadOffset; // current head position
    LLAvatarJoint*         mRoot;
 
-   typedef std::map<U32, LLJoint*> joint_map_t;
+   typedef boost::container::flat_map<U32, LLJoint*> joint_map_t;
    joint_map_t            mJointMap;
 
    LLVector3            mBodySize;
    LLVector3            mAvatarOffset;
 


2020-10-08 01:15:16
Profile

Joined: 2009-03-17 18:42:51
Posts: 5523
Reply with quote
Yep, flat maps (and sets) are an interesting topic to optimize the code execution time.

I explored this possibility last summer, with a systematic approach, i.e. converting all boost::unordered_map and boost::unordered_set containers with various flat containers alternatives (I tried phmap::flat_hash_*, tsl::hopscotch_*, tsl::robin_*, robin_hood::unordered_flat_*).
Sadly the result was a randomly crashing viewer and no real obvious speed-up (no significative change in frame rates).

The delicate point is that most flat containers got limitations (iterators invalidation and changing pointers to values, mostly), and even when taking those into account, these implementations are not bug-free, obviously. I therefore abandoned the idea...

Your targeted approach (i.e. using the profiler to spot the places where such optimizations would be most welcome/useful) is definitely the way to go. Also, I did not try boost::container::flat_map, which may be safer (if slower) than the more modern alternatives I tried.

I'll try your patch with v1.28.1 and see if it is safe (no crash): if it is, will adopt it.

Thank you !


PS: I'm attaching here the (latest version of the) result of my last attempt at fast containers in the form of a patch (that would have to be applied to v1.28.0 sources, but that will likely lead to quite a few rejects since the code changed during the past months in the latter):
You will also need the fast-containers package:
EDIT: integrated in v1.28.2.33


2020-10-08 08:05:31
Profile WWW

Joined: 2009-03-17 18:42:51
Posts: 5523
Reply with quote
I refined my first boost containers replacement attempt, and the result can be experimented with in the 1.28.2.33 release published today (with the FAST_CONTAINERS option in indra/cmake/00-BuildOptions.cmake).

In particular, I found how to avoid the crashes I was seeing so far (basically, by keeping boost::unordered_map for the problematic maps, but a proper diagnosis would be required to determine why the crashes happen in the first place, even if the prime suspect is a bug in the container implementation).

Still, a more thorough and intensive testing is required before I would adopt any such new container for release viewers.

The phmap implementation (a header-only re-implementation of absl containers) seems the most promising one. Under Linux, I can see a detectable frame rates boost (around 2 to 5%) over classical boost containers...

Feel free to test and report your findings in this thread...


2021-07-17 12:29:04
Profile WWW

Joined: 2016-06-19 21:33:37
Posts: 337
Location: Columbus area, OH, USA
Reply with quote
Henri Beauchamp wrote:
The phmap implementation (a header-only re-implementation of absl containers) seems the most promising one. Under Linux, I can see a detectable frame rates boost (around 2 to 5%) over classical boost containers...

Feel free to test and report your findings in this thread...

I decided to give phmaps a try this weekend, since I always build the viewer for my specific 'rig' and to enable the newer curl (I haven't had any rainbow texture issues). I will say, I see a little increase in my fps with phmaps too. A bit more than Henri reported at roughly 5-10%, but no rigorous measurements. I have not experienced any crashes so far and have been using this build for a couple of days.


2021-07-18 21:53:49
Profile

Joined: 2009-03-17 18:42:51
Posts: 5523
Reply with quote
I finally only kept the "parallel hashmap" containers as an option for replacing boost ones, and enabled them in today's v1.28.2.34 release. Let's see how they will fare on a larger users base...


2021-07-31 08:53:36
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.