BradleyB's WebLog

Tips to optimize design-time build performance for Web Sites in Visual Studio 2005

There have been a number of posts with tips to improve build performance within Visual Studio 2005.  I've consolidate these posts and other tips into a single post of techniques for common problems.

Do not disable batch compilation
Make sure web.config does not have <compilation batch="false" />
The default is “true” so unless it’s explicitly set to “false” you’re ok.

Some post have recommended disabling batch compilation to address a migration issue with circular references.  Unfortunately this dramatically impacts build performance.  You're much better off addressing the circular references than to disabling batch compilation.

Leverage Server-side Compilation
Visual Studio 2005 is leveraging ASP.Net 2.0 server-side compilation.  The IDE is primarily validating that the site will compile.  For most edit/run iterations it's not really necessary to validate/build the entire site on every F5 or solution build.

Change Build options for the web site project:  (Property pages <shift>F4 -> Build)
    “Start Action (F5)” should be either "build page" or "no build".  -  Improves F5 performance
    “Build Solution Action” uncheck “Build Web as part of solution.”  -  Makes <ctrl><shift>b very fast.

While this does improve build performance because ASP.Net is only compiling the files needed for the request on F5, it doesn't help the developer identify all the compilation issues within the IDE before running.  There are a couple of techniques you an use to help with this.
  1. Move App_Code files into a separate class library project and reference it form the web site project.  This will improve build performance and provide all compilation errors for these class files within the IDE.
  2. Add a Web Deployment Project to the solution.  Configure the Web Deployment project so that it only builds for the release configuration.  This will allow you to completely validate the site before deployment without compromising the performance of the edit/run iterations under the debug configuration.

Move App_Code files into a separate class library project
I'm repeating this tip because even if you don't change the default build options you can improve build performance by moving the files from App_Code into a separate class library project.

Check for conflicting dependencies
If you do have conflicting dependencies, the web site project will do a full clean rebuild on every build even if only a page changes.  The problem is when you add a file based references that have a common dependency but to different versions of that dependency.   A file based references have a .dll.refresh file in the bin folder.  The .refresh file has the path to the original assembly.  These paths are checked on every build.

In this example we have two assemblies, A.dll and B.dll both dependent on Foo.dll.

    A.dll -> dependent on Foo.dll
    B.dll -> dependent on Foo.dll

When A.dll is refreshed the project system will discover the dependency on Foo.dll and copy it into bin. Likewise when B.dll is refreshed Foo.dll will be copied if different than the one already in bin. The problem is that when a class library is built by a class library project in VS it caches the dependencies. So as you can see here Class Libraries A and B both have a private copy of Foo.

ClassLibraryA
    A\bin\debug\A.dll
    A\bin\debug\Foo.dll

ClassLibraryB
    B\bin\debug\B.dll
    B\bin\debug\Foo.dll

ClassLibraryFoo
    Foo\bin\debug\Foo.dll

If ClassLibraryFoo is updated and only ClassLibraryB is recompiled then ClassLibraryB has a updated copy for Foo.dll but ClassLibraryA does not. When the web project is built, the refresh of A is copying in it's copy of Foo and the refresh of B is copying in it's copy. Each time Foo is copied because it's different than the one already in bin.

Because the bin is changing with every VS build the ASP.Net compilation cache is invalidated forcing a full build.  Thus every build is a full build.

To fix this problem do one of the following:

  1. Add class libraries A,B and Foo to the same solution as the web site and replace the file base references with project references.
  2. Always build all consumers of a dependency when the dependency changes.
  3. Remove the .refresh files and manually update as needed.

Turn off AutoToolboxPopulate in the Windows Forms Designer options. 
Some user have reported a hang during build.  This was resolve by turning off AutoToolboxPopulate.
http://forums.asp.net/1108115/ShowPost.aspx

    Tools/Options/Windows Forms Designer/General/AutoToolboxPopulate = False

Disable validation for HTML editing
By default the HTML/ASPX editor performs html validation in the background while the file is open.  This does not normally impact performance unless there are numerous error to report.  So if you're already compliant, turning it off won't save you much but if you do have errors and don’t' need to fix them, turning if off can make a difference. 
http://msdn2.microsoft.com/en-us/library/0byxkfet.aspx


You'll be surprised at the performance improvement these changes will make for the edit/run iterations of your daily workflow.  My sample solution with 2 class libraries and 1 web site went from 17 seconds to build to less than a second.  While these techniques may not be right for every project, the improvements are significant enough that you should try them out and evaluate them for yourself.

Hope this helps,
Brad.

Comments

Jason said:

Personally, the biggest performance increase in compiling I found was to change the projects target platform from "Any CPU" or "Mixed Platforms" to "x86". Went from ~10 seconds to "did it actually compile?.. wow, that was fast."
# December 7, 2005 11:08 AM

vijay kumar said:

Hi,

   Recently i have converted vs2003 project to vs2005

Then all problems started.I followed all the tips u said.I removed refresh.dll in my bin folder. I have unchecked show error in options/text node/validations. Even then rebuild takes approx 5-7minutes.I am using window 2000 with 256 ram

   Becoz of conversion i am getting all these problems? or

becoz of low system resources?

   My project contains around 80 pages with 2 class library projects.I am using atlas framework in my project.

   Plz suggust me something to improve performance.

# August 29, 2006 2:03 AM

D said:

I just upgraded my machine :) Compiles in a flash now...

# October 4, 2006 8:38 AM

Nico said:

Interesting. I just found out that setting batch=false lets me start my asp.net 2.0 web app 10 times faster on my local machine! Also I dont get that annoying "no relevant source lines" error anymore when I start debugging.

Turning batch=true means that all your stuff within one directory is compiled into one dll at once. Switching batch=false means dll's for every single page. As I mentioned, on my machine the batch=true option is very very slow. Every time when I start debugging by F5 the whole app is compiled and for every page a xml file must be generated and so on... Turning off batch compilation makes start debugging rocket fast. So I have to wonder about the suggestion above:

"

Some post have recommended disabling batch compilation to address a migration issue with circular references.  Unfortunately this dramatically impacts build performance."

For me it's a real performance boost to use batch=false!?

And now I'm wondering why this is so totally different to your post? Any hints?

# November 15, 2006 5:23 AM

oneddtest said:

Optimize design-time compilation in Visual Studio 2005

# August 6, 2007 11:17 PM

tips optimize game performance said:

Pingback from  tips optimize game performance

# July 5, 2008 1:01 PM

vahila said:

please add our website

# July 18, 2008 6:26 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)