So, I am creating a library that will have a class someBase {}; which will be displayed by downstream users in several classes.
class someBase { public: virtual void foo()=0; };
What I also have is a vector of pointers to someBase, and I do this: -
vector <someBase*> children;
Profiling now shows that incorrect branch predictions on virtual calls are one (of several) bottlenecks in my code. What I want to do is somehow get access to the RTTI objects and use them to sort the vector of children according to the type of class, in order to improve both the locality of the command cache and branch prediction.
Any suggestions / solutions on how to do this?
Key issues to consider: -
1.) I really do not know which or how many classes will be derived from someBase. Hypothetically, I could have a global enumeration in some common file somewhere that lower-level users can edit to add their own class type and then sort it (mainly using my own RTTI). But this is an ugly decision.
2.) PiotrNycz suggests using type_info in his answer below. However, only! = And == are defined for this. Any ideas on how to get a strict weak order on type_info?
3.) I really try to improve the location of branch prediction and the localization of the command cache, so if there is an alternative solution, this is also welcome.
owagh source share