Sign in to follow this  
_damN_

Large source(.cpp) files?

Recommended Posts

_damN_    127
This might sound like the dumbest question ever but can excessively large source files make a program run slower after it has been compiled? Is so, what would be a reasonable amount to put in a file? Thanks!

Share this post


Link to post
Share on other sites
Antheus    2409
Typical cpp will be anywhere between several and up to hundred or so megabytes after pre-processor. This is what is actually used to generate the .obj file. Compilers have options to output this file so you can check yourself.

Unity build uses a single .cpp file which includes all other cpps and all headers. After pre-processor, it can get to hundreds of megabytes in size.

This is what compiler and linker need to work with anyway, so source has no impact on generated code on recent compilers which can eliminate redundant and duplicated code.


Also a fun fact, some 90% of typical build is spent searching for, and parsing headers. Designing a build system around this fact to operate on pre-processed files can speed up build times by a factor of 10-100, especially if boost is involved. It does complicate debugging though.

Share this post


Link to post
Share on other sites
jpetrie    13159
Quote:

This might sound like the dumbest question ever but can excessively large source files make a program run slower after it has been compiled?

At runtime? No, not really.

Share this post


Link to post
Share on other sites
Facehat    696
Quote:
Original post by _damN_
This might sound like the dumbest question ever but can excessively large source files make a program run slower after it has been compiled? Is so, what would be a reasonable amount to put in a file?

Thanks!


No it won't make it slower, but it's a (very obvious) sign that the class/module is too big and should be refactored.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this