   Compilation speed: .pch vs. less included
  Hello,currently I''m thinking about cutting down compilation times for a medium scale project I''m currently working on (~ 25k loc atm). I see two different possibilities:a) the good old "include what you need, where you need it" style. This means including only those headers actually needed at the top of each file. Following the simple logic "less files to parse means lower compilation time"b) creating a standard include which includes all regularly needed std and project headers and using precompiled header files for compilation speed up.While I came up with some pros and cons for both (mostly based on properties of the project and thus a bit hard to debate here..) I don''t come to a conclusion which one I should prefer..Could you give me some facts or founded opinions speaking for or against the both possibilities?[Edited by - cmdkeen on May 19, 2008 8:30:37 PM]
  I use a combination of both. I only include what I need where I need it, but I use a PCH for the Windows and OpenGL includes. Doing so has speeded up compilation time IMMENSELY.   "Sneftel is correct, if rather vulgar." --Flarelocke ;  But the speed-up only comes around when you have ''finished'' the code that used the pch. eg: Once it''s almost done and in a lib, it''ll help a bunch. Other than that, if you''re working on your game and still trying to create the PCH, it''ll not help if you''re changing headers and such.At least that''s what I''m suffering from. ;  I don''t think you are supposed to modify your .pch.Anyway, I don''t like precompiled headers. I don''t know why, I used to use it, and it made some headaches at some point, maybe it''s my fault or something I don''t know, but I have decided not to use it anymore.I include files when necessary. After all, if they are not modified, they are not going to be recompiled, thus speeding up the compilation time. I''d say to include files when necessary, and have a good design/plan before coding (to reduce changes to the core files). ;  The two techniques aren't mutually exclusive. You should be using both if you want reasonable compile times in all but the most trivial apps. Common system include files (such as windows.h) should go into a precompiled header and included wherever they are used.Edit: don't misunderstand PCH's. When the engine is still in flux and everything is changing the header should contain only system include files, which never change. Don't add your own headers to PCH unless you know it won't change much. I think anytime one of the headers in a PCH changes, the other thing has to be precompiled yet again.   [edited by - antareus on February 7, 2004 7:14:48 PM]