Patrick Smacchia [MVP C#]

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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.

 


Posted 06-20-2007 6:15 PM by Patrick Smacchia

[Advertisement]

Comments

» Benefit from the C# and VB.NET compilers perf wrote » Benefit from the C# and VB.NET compilers perf
on 06-20-2007 12:57 PM

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

Peter Ritchie wrote re: Benefit from the C# and VB.NET compilers perf
on 06-26-2007 11:30 AM

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

Arjan wrote re: Benefit from the C# and VB.NET compilers perf
on 09-26-2007 5:15 PM

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.

Arjan wrote re: Benefit from the C# and VB.NET compilers perf
on 09-26-2007 5:29 PM

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

Patrick Smacchia [MVP C#] wrote Hints on how to componentize existing code
on 12-16-2007 11:31 AM

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

Patrick Smacchia [MVP C#] wrote Lessons learned from a real-world focus on performance
on 12-01-2008 4:32 AM

I am glad to announce that we just released a new version of NDepend where the analysis phase duration

Community Blogs wrote Lessons learned from a real-world focus on performance
on 12-01-2008 4:55 AM

I am glad to announce that we just released a new version of NDepend where the analysis phase duration

Lessons learned from a real-world focus on performance - taccato! trend tracker, cool hunting, new business ideas wrote Lessons learned from a real-world focus on performance - taccato! trend tracker, cool hunting, new business ideas
on 12-02-2008 10:16 AM

Pingback from  Lessons learned from a real-world focus on performance - taccato! trend tracker, cool hunting, new business ideas

Lessons learned from a real-world focus on performance - taccato! trend tracker, cool hunting, new business ideas wrote Lessons learned from a real-world focus on performance - taccato! trend tracker, cool hunting, new business ideas
on 12-03-2008 11:03 AM

Pingback from  Lessons learned from a real-world focus on performance - taccato! trend tracker, cool hunting, new business ideas

Lessons learned from a real-world focus on performance - taccato! trend tracker, cool hunting, new business ideas wrote Lessons learned from a real-world focus on performance - taccato! trend tracker, cool hunting, new business ideas
on 12-04-2008 11:09 AM

Pingback from  Lessons learned from a real-world focus on performance - taccato! trend tracker, cool hunting, new business ideas

Add a Comment

(required)  
(optional)
(required)  
Remember Me?