Page 1 of 1

Ogre STD Headers

Posted: Wed Jan 08, 2014 12:06 am
by Klaim
I didn't made yet a deep analysis of the situation but I would like to ask experts and the Ogre team:
Am I correct that the header OgreStdHeaders.h is certainly the biggest source of compilation time in Ogre?
It is included in OgrePrerequisites.h , which is included in almost all Ogre headers, and it have this kind of thing:
#include <fstream>
#include <iostream>
#include <iomanip>
#include <sstream>
I was trying to understand why this header even exist, maybe it was because of a precompiled-header setup, but it looks strange because totally bloated.

Re: Ogre STD Headers

Posted: Wed Jan 08, 2014 3:01 pm
by dark_sylinc
Ogre needs a session of analyzing all headers and removal of bogus dependencies. But no one's found the time yet, and I don't know about tools in aiding this (AFAIK the boost guys build their own tool to visualize include headers)

It appears to be included in OgrePrerequisites so that the "std headers" get included after all macro settings have been set, mostly to deal with compiler variations i.e.:

Code: Select all

#if (OGRE_COMPILER == OGRE_COMPILER_GNUC) && !defined(STLPORT)
#   if OGRE_COMP_VER >= 430
#       include <tr1/unordered_map>
#elif (OGRE_COMPILER == OGRE_COMPILER_CLANG)
#   if defined(_LIBCPP_VERSION)
#       include <unordered_map>
#   endif
However, IMO including std headers in all files is insane (other than vector and string).
Though I don't think the problem is a single file, but rather that every file ends up including almost every file.

Re: Ogre STD Headers

Posted: Wed Jan 08, 2014 3:54 pm
by Mikachu
A while ago I tried to dig into the problem of Ogre headers, but never quite finished the work...

Here's what I found :
- There's this little tool analysing which header includes what in a C++ project : https://bitbucket.org/bitsquid/header_hero/downloads (but it doesn't perform any analysis about compile time for each header, which could be handy)
- There's massive inclusion between Ogre headers.
One cause for that used to be shared ptrs, as they needed to know the full type of the class they were pointing at.
I submitted a patch for this, but didn't have the time/courage to run an analysis to see what heaer dependencies could be subsequently removed.
- Another cause for massive inclusion is sometimes use of inner typedefs/constants/enums : instead of forward declaring the class in the header, you need to include its header.
- All of that process of improving compile times is a hard task, but would be very useful to the community (compiling Ogre itself is no longer a problem with unity builds, but every project using Ogre get bad compile times because of headers)

Re: Ogre STD Headers

Posted: Wed Jan 08, 2014 4:30 pm
by Klaim
Interesting points. I'll think for a battle plan to help on this in a few months (when I'll have time a bit more time to apply the plan).
I think it is not natural, even for C++, that Ogre take so much time to build (ignoring the unity build mode).

Re: Ogre STD Headers

Posted: Wed Jan 08, 2014 4:48 pm
by Mikachu
I forgot to say, I'm currently trying to write a pimpl interface generator for Ogre, which would solve those issues from a user point of view, but I'm still not sure I'll succeed (containers/templates of Ogre types don't mix well with the pimpl idiom)

Re: Ogre STD Headers

Posted: Wed Jan 08, 2014 6:28 pm
by Klaim
Mikachu wrote:I forgot to say, I'm currently trying to write a pimpl interface generator for Ogre, which would solve those issues from a user point of view, but I'm still not sure I'll succeed (containers/templates of Ogre types don't mix well with the pimpl idiom)
Oh wow, that would be very useful!