Jump to content

Improving visual studio performance?


Josh
 Share

Recommended Posts

Is there anything I can do to improve the performance of the visual studio compiler? If I only change the main code file, it takes 20-30 seconds to compile a small project. GCC compiles a similar project in less than a second.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Is this something that gets set per-file? I looked at the options and there's one setting to use a pch and another to create one...I am a bit confused, and Google did not help.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Make one header file that includes most of the system includes and

your most common includes. Then include that header file first thing in each source file.

Name it anything you want, lets say leheaders.h

#pragma once

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

#include <string>

#include <vector>

#include .....

#include .....

etc etc etc.....

 

Make one leheaders.cpp that contains one statement

#include "leheaders.h"

 

In project properties

Set C++ settings "Precompiled headers" to "Use"

Precompiled Header = leheaders.h

 

Select leheaders.cpp and Properties

Set C++ settings "Precompiled headers" to "Create"

 

This will precompile your headers so they don't need to be parsed and compiled

on each project compile. The only time precompilation is done is when you change

something in the header files included in leheaders.h or if you selects rebuild.

 

You must include leheaders.h as first include in all your sourcefiles.

 

Also check that "C++/Browse Information" is "No"

 

Edit:

"C++/Code Generation/Enable Minimal Rebuild" should also be set to "Yes"

"C++/General/Debug Information Format" set to "Program Database (/Zi)"

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

I thought VS handled only compiling files that have changes in them by default?

 

Thats true, but I'm not talking about compiling source files.

Here we are speeding up things by using pre-compiled headers (not cpp).

Normally the compiler has to pre-compile each included header every time when in compiles a source file.

That takes time. The option to use pre-compiled headers makes this pre-compilation only needed when any

of the included headers changes. This results in a faster compilation as you normally make changes in the

cpp files. The compilation time can be improved a great deal in big projects.

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

What would be the harm to just make all headers pre-compiled?

 

You need one header that is the target for pre-compiling, in our example its the leheader.h.

Which headers to be included in the pre-compilation is defined by you when you include

other headers in leheader.h. This way you can tell which headers to be pre-compiled and not.

 

The natural thing is to add all system/sdk/stdlib-headers there as the never changes.

Then you could add your own headers that you don't change so often. One suggestion is

to include the ones that are stable and have the experimental ones not included. Then

when the experimental ones become stable you can include them.

 

In previous versions of VS there was an alternative where you could tell to use all headers

as precompiled. That options was removed as it did not work well at all (I don't know why as I never used it).

Anyway, since the Jura-period they have recommended the method used now.

 

Hope that this helped a bit

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

or you should include only headers, which you really need.

 

Sometimes, when you change one header, it have to compile all other affected headers and sources.

You can try add few preprocessors like:

 

#ifndef MYHEADER_H
#define MYHEADER_H


your code


#endif

 

but precompiled headers should work :lol: but i think, you will change them a lot sometimes :P

-= Phenom II X4 965 3.4Ghz - ATI HD5870 - 6 GB DDR3 RAM - Windows 8 Pro 64x=-

Website: http://www.flamewarestudios.com

Link to comment
Share on other sites

or you should include only headers, which you really need.

 

Sometimes, when you change one header, it have to compile all other affected headers and sources.

You can try add few preprocessors like:

 

#ifndef MYHEADER_H
#define MYHEADER_H


your code


#endif

 

but precompiled headers should work :lol: but i think, you will change them a lot sometimes :P

 

You should always do this in any case.

You can preferable use the new way of doing this in all headers

#pragma once

your code 
....
....
...

 

This has nothing to do with compilation speed. This is a way to avoid double declarations

in nested includes.

 

Regarding changing headers often while developing you can go this way.

 

Include all your own headers in the pre-compiled header when they are stable.

This means that while you are changing things often in a header while working,

you should not include this header in the pre-compiled header. Then when your

work is more stable and does not change to often you may include the header file

in the pre-compiled header.

 

A little religious note about this:

----------------------------------

Making frequent changes in header should not be needed if you have thought things through

before hitting the keyboard. When I write code I try to write the headers first with all that

should be needed. Then I go into implementing the headers. If I then have to make a change

in a header it should be more of an emergency and tell that I did not think enough before

starting with the code. Of course this is true in a perfect world and of course I have to

change my headers now and then. But in general they should not have to be changed to often.

 

If you have to make changes in the headers often, it may be pointing to the fact that you

are creating to big classes. Always try to break things down to as small pieces (classes) as

possible and don't fall into the trap of having four of five giants taking care of all.

 

This is my personal notes. Others may think different. But I thought it could be mentioned

here as a note about pre-compiled headers.

----------------------------------

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

I'm getting this error with my project:

1>..\LuaJIT-1.1.6\src\lopcodes.c : fatal error C1853: 'Release\LE3.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)

A search indicates this has to do with the fact I am including Lua/Lua-Jit, which is .c files (not .cpp). I can't find any solution to this for Visual Studio 2008.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I'm getting this error with my project:

 

A search indicates this has to do with the fact I am including Lua/Lua-Jit, which is .c files (not .cpp). I can't find any solution to this for Visual Studio 2008.

 

For such external source files (c or cpp which you have no control of) added to project you have to select them and go into properties. Change those to "Not using precompiled headers". They do not have the #include "your precompied header file.h" as fist statement and cant be used for this.

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

1>Linking...

1>Vec3.obj : error LNK2011: precompiled object not linked in; image may not run

1>C:\Leadwerks 3\Engine\engine\Release\LE3.exe : fatal error LNK1120: 1 unresolved externals

 

:blink:

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 1 month later...

Sorry for picking up old topic, but recently Ive decided to figure out with precompiled headers, but cant understand some things on practice.

 

So in the case of our LE projects, what is the right way to configure it?

I mean we have engine.cpp and a lot of leo.cpp files that can not have #include "your precompied header file.h" but they do use some standard headers like "windows.h" and as I understand its better to place them in precompiled headers. Also the engine.cpp and leo.cpp dont change rapidly so they should use precompiled headers too, shouldnt they?

 

 

Thanks in advanced.

Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64

3ds max / photoshop CS3 / C++

http://www.arbuznikov.com

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...