0

Lets say I have

A) Visual studio solution with several projects (libraries for the main application with sources that are compiled too), they result in lib files that are used in the final linking.

B) Lots of tiny functions called across the project and libraries that I need to be inlined in final release to maximize performance.

C) But I also want to minimize include dependency and messy headers (as from what I understood method body has to defined in body to make inlining possible), to minimize compiling speed during developing process.

I was thinking about making special "Final release" project, that would contain one "all-in-one.cpp" module, that would simply #include all the cpp modules from all libraries in the solution, so compiler would see all method bodies and could optimize everything it needs.

From what I have seen the "Whole program optimization" should do this job for me, but only for one project.

Edit: Is there similar option when compiling under linux with g++?

Edit: I just made project that has one cpp that includes all modules I use so I can use inline defined in cpp, the inline worked, and in my case it drastically bossted performance.

Edit: No whole program optimisation does NOT allow the inline function implementation to be defined in cpp (http://msdn.microsoft.com/en-us/library/78t98006%28v=vs.100%29.aspx) and YES, the all-in-one module method seems to be the only reasonable way for relase build I found

Edit: But I was also surprised by the speed of the compilation, the project compiles several minutes when divided into compilation units (100 modules), but when I compile it as one cpp it compiles in several seconds.

4

1 回答 1

4

Have you profiled your code? If not, don't wander into making these changes.

Also, whole program optimization works on the whole solution, not just one project. It even says so in the link. Let the compiler do its job in optimizing the code, and just worry about having a clean, organized structure with code that's easy to read an understand.

于 2012-05-04T07:06:35.143 回答