CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Patrick Smacchia [MVP C#]


Benefit from the C# and VB.NET compilers perf

 

I think that the performance of the C# and VB.NET compilers are truly awesome. The 30.000 C# LOC (Lines of Code are expressed in terms of PDB sequence points as defined here) of the VisualNDepend project are compiled in 5 seconds on a regular CoreDuo 32bits 2GB computer. In fact, most of the time it takes even less than a second thanks to the caching optimization provided by the C# compiler/VisualStudio. This performance highly increases our productivity, not only because it saves time, but also because it saves a lot of frustration.

 

My main activity, apart developing NDepend, consists in auditing projects of tiers company. I’m always amazed to see that most of real-world C# and VB.NET app take minutes or even dozens of minutes to be compiled.  Although it could be justified for monolithic huge application (>500K LOC) it appears that this performance problem arise on small projects that should take seconds to be compiled. I also noticed that this poor performance is widely accepted because people often come from C++ where compilation durations were hours.

 

I mainly identified 3 causes that each can dramatically slow down compilers. When these causes are pipelined, seconds are transformed in minutes and the developers’ productivity and motivation decrease significantly.

  • First, developers should make few big projects instead of numerous small projects. I didn’t find any relevant information on internal compilers optimization, but experience shows that when multiplying the number of projects, the compilation time increase dramatically (10 project of 10K LOC will take much more time to compile than a single project of 100K LOC, I would say around x2). It seems that the unit for compilers’ optimization is the project. Structuring your applications with the adequate grain for assemblies and namespaces is a subject I investigated within this article.
  • Second, the referenced assemblies option ‘Copy Local’ is deemed as a good practice. It allows exhibiting for each of your assembly the set of assemblies it transitively depends on. However, we have to realize that this practice triggers numerous file copies behind our back and here also it seems that it enormously hampers compiler optimizations. My advice is to always set ‘Copy Local’ to false and to toss all your assemblies in a single folder such as ${AppFolder}$\bin\Debug and ${AppFolder}$\bin\Release. Not only you’ll accelerate compilation, but also you’ll rationalize the entire development process by minimizing the overall number of files under your precious ${AppFolder}$. Here also experience shows a gain of x2 to x3.
  • Third, the source code manager system can also disturb the compilers’ optimization work. I experienced a x3 to x4 penalty when using ClearCase’ dynamic views mode. This point should be investigated carefully because each source code manager system has its strengths and weaknesses. You should be aware that if you experience abnormal long compilation duration, rationalizing the way your source code manager system is used (with a snapshot mode for example) can dramatically help you.

Of course, having big assemblies, don’t use copy local and getting rid of some cool source code manager facilities can be a difficult choice to do, especially when the number of developers working concurrently is high. But it seems to be the price to pay to save a lot of precious time.

 



Comments

» Benefit from the C# and VB.NET compilers perf said:

Pingback from  » Benefit from the C# and VB.NET compilers perf

# June 20, 2007 12:57 PM

Peter Ritchie said:

Sounds like compiler vendors need to focus their attention on linkers and librarians in terms of performance work...

# June 26, 2007 11:30 AM

Arjan said:

I tried it by moving 5 projects into 2. It maybe saves me 10% to 20%, no more, this includes the copy local setting. I have about 70.000 lines of C# code and it takes about 16 seconds to complete, on my AMD 3GHz notebook.

# September 26, 2007 5:15 PM

Arjan said:

Visual Studio 2008 (beta 2) compiles in 13 seconds where 2005 takes 16 seconds :)

# September 26, 2007 5:29 PM

Patrick Smacchia [MVP C#] said:

Representing the structure of a code base with a DSM (Dependencies Structure Matrix) is a great mean

# December 16, 2007 11:31 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Patrick Smacchia

Patrick Smacchia is a Visual C# MVP involved in software development for over 15 years. After graduating in mathematics and computer science, he has worked on software in a variety of fields including stock exchange, airline ticket reservation system as well as a satellite base station at Alcatel. He's currently a software consultant and trainer on .NET technologies as well as the lead developer of the tool NDepend which provides numerous metrics and caveats on any compiled .NET application. He is the author of Practical .NET2 and C#2, a .NET book conceived from real world experience with 647 compilable code listings. Check out Devlicio.us!