Branislav Abadjimarinov's technical blog

How to speed up compilations in ASP.NET Web Site

Posted in ASP.NET, Virtualization, Performance by Branislav Abadjimarinov on 2/2/2010 11:18:00 AM - CST

When working with ASP.NET most developers, including me, choose to use the Web Site model. One of the reasons for that is the smooth working process. If you make a change in your website you do not need to manually recompile - does that for you. But because of this change there is a slight delay before the site starts again. There are several tricks to decrease this time to minimum.

1) Use the optimize compilation option. It was introduced with a hotfix for .net 3.5 sp1. You can find it here -
 In general on change in App_Code, web.config or Global.asax file ASP.NET wipes the temporary files and generates new. This option allows ASP.NET to generate only the changed part of the files and leave the others. The only thing you have to do to enable this behavior is to put in your web.config :
<compilation optimizeCompilations="true">
The fix is for Windows XP,Windows Server 2003, Windows Vista and Windows Server 2008.
If you're running Windows 7 or Windows Server 2008 R2 you already have this feature installed but you still need to enable it.

The first trick will take care of the redundant file generation but files still will be copied. The Second one will speed the copy and access process.

2) Keep your ASP.NET temporary files in the RAM. There are some programs that create a RAM disk - a hard disk partition that is persisted in the RAM. I personally use RAMDisk - it is free for hard disks bellow 4GB and you can download it from this address - The UI of the software is pretty simple - you have to choose size of disk in MB and Format.


The options for format are FAT16, FAT32 & Unformatted. You can use Also NTFS which I will recommend. You need to choose the Unformatted option. Then you Start the RAMDisk, go to Control Panel->Administrative Tools->Computer Management and in the left pane choose Storage->Disk Management. Right-click on the unallocated space and choose New Simple Volume. You'll be prompted to choose Letter for the volume - I usually choose R (for RAMDisk).


Now you should be able to see the new drive in Windows Explorer.


The only thing you have to do next is to change the path for your temporary ASP.NET files in web config's compiler section.
<compilation defaultLanguage="c#" debug="true" optimizeCompilations="true" tempDirectory="R:\ASP_NET_TempFiles\" >
On the next website request you'll see that the files will be populated on your newly created RAM disk.

The size of the disk depends on how big your project is. I usually use no more than 512MB - a good round number :-) .

If you want to keep the data in the virtual disk even when you shut down your PC you can persist the drive to image file (.img) from RAMDisk.

RAMDisk second tab


P.S. Have in mind that there are technologies that does put your most used files in the RAM automatically (for example Microsoft Super Fetch) but you do not have controll what does and what doesn't get cached. So just try this method and see if there are any improvements in web application start time.


Trackback  on 4/13/2010 10:23:55 PM - CST
Posted by RJ on 11/17/2010 7:30:46 PM - CST
I can't get the hotfix it looks like MS took it down.
Posted by Mr. Build on 9/13/2012 12:07:56 AM - CST
I think the RAMDisk thing you are using is not free if used for commercial purpose... the version that allows you to create a RAMDisk up to 4Gb is for personal use :)
I might be wrong anyway... need to double-check
Posted by Mr. Build on 9/13/2012 12:08:47 AM - CST
Yeah... just double-checked... I was right
Posted by Nicole Lee on 10/17/2012 7:06:21 PM - CST
Thanks, This is a good article
Posted by Ehab heikal on 3/26/2013 6:36:24 PM - CST
Had a problem with the redundant file generation, on a server did not realize how long I allowed this server to sit without proper updating. Thanks.

Add Comment

Please enter your name. Please enter a valid email. Please enter a valid website.
Please supply a comment.
© Copyright 2018 Powered by AtomSite