Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does having more projects in your visual studio increase compile time?

Which scenario below would compile faster?

  1. Two projects inside of a solution. Each project has 5 classes.

  2. One project inside of a solution. The project has 10 classes (the combination of the two projects in scenario a).

Basically, I'm trying to see if having 2 projects would affect the compile time in a solution.

like image 227
Saturn K Avatar asked Dec 01 '09 19:12

Saturn K


4 Answers

Yes, in large C# solutions, having more projects makes compile time very noticeably longer (by many minutes). At least, that's my experience. However, I would add a caveat. I suspect that projects are compiled when it is not strictly unnecessary because C# is not all that smart about what it chooses to compile. So if most projects do not reference other projects much, it may not be such a problem. I can't tell for certain because the code I've worked on (legacy stuff, not mine, I hasten to add) that has this sort of problem is not loosely coupled from that POV.

Mind you, slow compilation is a feature of some languages (all the C-based ones, for example). Languages that can be compiled in a single pass (eg Pascal derivatives like Delphi), compile far quicker (10^6 LOC in seconds).

So there is a limit to how fast you can get anyway. It's mostly a hardware issue as compiling is very disk intensive (ie slow) for most languages (FLs can be an exception). Other threads here talk about ways to speed up VS compilation times, and the biggest improvement is always by getting a really quick HD, or better, a modern SSD.

like image 157
Jim Cooper Avatar answered Sep 28 '22 00:09

Jim Cooper


The compiler takes each class through references. The bottom layer (no internal project references) has to be compiled first, then the layers that reference other internal projects, and so on. Therefore, yes, the compile time will be slightly increased due to the fact that the compiler has to sort the references and create multiple binaries.

On the other hand, most large projects SHOULD be separated into multiple projects and namespaces for ease of readability and navigation. It really depends on what you're doing, but you could potantially put 1000 classes in a single file, or multiple files, or multiple files in multiple projects. The amount of time (minimal) saved in the compile time won't compare to the time wasted looking for stuff in a poorly laid out solution.

With a solution of 2 projects with 5 classes, the compile time will be milliseconds different from a single project of 10 classes. The linking and referencing is the only real increase you'll see, and that is minimal.

EDIT: On another note, if you have a project large enough that you're noticing a real difference in compile time, you should probably be considering implementing some sort of continuous integration (see: http://en.wikipedia.org/wiki/Continuous_integration) environment, which will keep a current build ready for you, as well as letting you know if something's broken.

like image 41
Nathan Wheeler Avatar answered Sep 27 '22 23:09

Nathan Wheeler


I would say yes, but I think the difference in time would be miniscule unless the files are very large (10k lines was when it started slowing down for me)

Note: the file I compiled with 10k lines was only because I was bored, I never actually used it for production, it was a lot of code I was migrating from previous projects into one.

like image 23
Stevoni Avatar answered Sep 28 '22 01:09

Stevoni


I would say yes, it does have an impact to have separate projects. A project is a standalone output and the linking would be different. It would have to also find dependencies from the references in the other project. The only way to find out is to try.

like image 22
Daniel A. White Avatar answered Sep 28 '22 00:09

Daniel A. White