In defining the CODE_ANALYSIS constant for projects within Visual Studio, the selected code analysis rules are executed upon each build. While this provides us with excellent suggestions on how to improve the code that we write, there is an obvious performance impact to the analysis of the source code upon each build.

So how can we improve the performance of code analysis?

One of the excellent new features of Visual Studio 2010 is test impact analysis where unit tests that have been affected by code changes can be determined and only those unit tests would be executed. Habib Heydarian, a program manager on Visual Studio, provides an excellent overview of the historical debugger and test impact analysis on Channel 9.

If we can use impact analysis for unit testing then why not use impact analysis for code analysis rule execution?

While it was test impact analysis that leads me to think about how to reduce the performance impact of code analysis, an alternative strategy also would seem to provide the required increase in performance. Why not provide another build option where the code analysis rules are executed only on those files that are currently checked out from source control?

If the solution open in Visual Studio contains twenty projects the chances are that a developer would only be working within one or two projects at a given time. Within those projects the developer would only have a few source files checked out from source control and these are the files the developer cares about at the present time.

With twenty or more projects within the solution the execution of the source analysis can seriously impact the time required to build the solution or even a few projects and their dependencies. It therefore makes sense that significant improvement in developer efficiency could be realized if the source analysis is executed only on code the developer cares about.

If you have been following my blog for some time you will have noticed that I use the Microsoft Connect website extensively for submitting feedback to Microsoft. I have therefore created a connect item for this suggestion and would appreciate it if you could vote for the suggestion and comment on the suggestion if you have an alternative strategy to solve the performance impact of source analysis on large solutions.