Oli's old stuff

Tinkering with retro and electronics

Jul 28, 2016 - 2 minute read - oldcode

Manta-X Code (Part 3)

Improving Compilation Time

Compile times on this 6094 loc project is much slower that it should be.

A full rebuild (including TinyXml):

Time Elapsed 00:03:00.35

There’s a bunch of reasons, but one of them is poor header discipline.

The all-emcompassing header

In every header file (and therefore every cpp file), there is #include "StdHeaders.h" at the top.

This StdHeaders.h file is some stupid include file that has a bunch of “common” junk in it. This is:

  • SDL headers
  • OpenGL headers
  • Windows headers
  • Tiny XML headers
  • A load of standard library headers
  • Singleton.h
  • IMMO.h
  • …and more!

So a whole bunch of crap in every file, regardless if it’s needed or not.

The first thing to do is just jump in and delete this damn file, then fix any compilation errors.

This took about an hour of removing all references to this header and including the right headers in the files. Note, I’m currently not forward declaring anything - I’ll do that in the next pass.

Compile time now:

Time Elapsed 00:01:53.19

We’ve shaved just over a minute off the compile time by cleaning up the “god header”, cloc says that at 6056 we’ve also shaved off some code.

The thing to look at next is to start removing unnecessary includes from the headers themselves.

Forward declarations & Unnecessary includes

The easy win here is to tackle the rendering system. It seems all of these files like to directly (or indirectly) include Reader.h, which in turn includes windows.h, gl/gl.h and gl/glu.h - rather large files to be bringing in every time.

Removing Render.h including only what is needed in just the texture rendering code improves the compile time somewhat:

Time Elapsed 00:01:25.33

That’s almost 30 seconds faster.

Clearing out some more in the model system:

Time Elapsed 00:01:18.18

And some more in the Entity system:

Time Elapsed 00:01:15.47

And pretty much everything else:

Time Elapsed 00:01:12.81

Using proper header discipline reduced the compile times of this ~6000 loc project by more than half.

It goes to show that best practices are there for a reason.

In cleaning out the code, I removed some unreferenced headers (that wouldn’t compile) - so cloc is now at 5990. Ideally, I’d not be counting the TinyXml build time in this at all - so perhaps that’s another avenue.

Next Time

Next time, I’ll go about actually getting this thing rendering again. The code is all there, but commented out. Not sure why, possibly due to the transition to SDL.