Taking to much time compiling

#1

Hi there.
I’m new to openFramework and i’m not sure if its normal for my project taking around 20 seconds to compile. It seems way to much time, sometime I just want to change something small like a color or something and just have to stare at the screen for a while until its done.
When I build it in the terminal it seems that a lot of what it’s doing could be precompiled or something.

Edit:
I’m with a 2012 13’’ MacBook Pro running macOS 10.14.

#2

In what platform?

#3

I’m with a 2012 13’’ MacBook Pro running macOS 10.14.

#4

What version of Xcode? what version of OF ?
if you go to project settings, what does it say?

#5

I’m using Xcode 10.2.1.

#6

Build times have seemed normal to me in xcode. Not to be annoying by stating the obvious, but of course it depends on what the project is like, and how its files are organized. If there is a lot of code which does for example #include “ofApp.h”, and the value you’re editing is in that file, then of course everything including that gets rebuilt.

#7

It would be very nice if there was an article showing what leads to faster compilation, with code examples and corresponding compilation times (some things have an effect, other things maybe not so much). And maybe approaches to reduce waiting times (build GUIs to be able to change things without recompilation, reloadable config files, etc). Maybe we have figured out different tricks, but I haven’t found a post about it.

#8

Yes, more writing about how some things can be done would be good. Especially as some APIs still lack much documentation. There is a really nice intro video series being posted on YouTube with links on r/openframeworks and here, though that’s not quite the same thing.

As for compilation times, there might be some OF-specific things to say about that, but I think in general it’s going to be the same issues and techniques with any C++ project, which is mainly about how you break your project up into files and what files you #include.

So:

  1. If you put all your project code in a few files, the compiler will need to recompile much more than if you break things into smaller files.

  2. Many files may want to #include #ofApp.h, so try not to define very many of your own elements in ofApp.h, because when you change #ofApp.h, everything that #includes it will need to be recompiled.

  3. You can break out part of a .cpp file into other files to avoid recompiling the whole file. If you have every significant function in its own file, and break complex functions into their own functions in their own files, then when you edit one, only that file will need to be recompiled. So instead of having ofApp.cpp contain the implementation for updates, drawing, responding to things, break those out into separate files.

  4. Avoid unnecessary #includes, and see if you can #include things only from the .cpp files that need them, not in .h files that may be included from several files.

  5. If you do have a file with many things in it and/or that is #included by many files, and you need to edit it, consider changing everything you’re about to want to change in it at once, rather than rebuilding each time you change one thing.

1 Like
#9

i remember that once i helped a friend with slow compilation time on xcode, the oF project was being compiled always by just one core, i found a way to make it work with all the cores but i don’t remember it now,

so check out for how many cores are running when compiling (more than one file), this could be the reason

#10

Great points.

One thing I learned to do was to include the files at the “bottom of the chain”. It’s tricky to figure out and I find it hard to explain without a bunch of examples how to browse the OF source code and figure out where things are declared. Sometimes it’s in OF, other times it’s in its libraries or in std.

Less experienced people may include ofMain.h everywhere just because they need a vector, a string, an ofColor or an ofRectangle, and it’s not ideal.

#11

if you use precompiled headers, which xcode does by default and qtcreator allows to enable through a flag in the projects qbs, including ofMain.h instead of separate headers is actually faster

#12

So maybe I got that wrong? I had understood it was not a good idea to include ofMain.h everywhere instead of more specific headers.

What’s the qbs flag for precompiled headers?

#13

yeah it was but precompiled headers turn that around. the precompiled header is around 300Mb per project so they are disabled by default in qt. the flag in the qbs project is there when creating a new project with the wizard and is called precompileOfMain just set it to true to get precompiled headers.

precompiled headers were only introduced in the very latest version of OF for qt projects so you might need to reinstall the wizards to get the flag in the qbs project file