Speeding up build times in ASP.NET with RamDisk
Here is another quick tip on how to speed up build times on your ASP.NET website projects: create a ram-based drive (i.e. using RamDisk) and change your default “Temporary ASP.NET Files” to this memory-based drive.
Then every time you change your ASP.NET pages (or any code-behind or reference DLLs) the build will happen much faster because is doing all in memory.
So, how you do this? Simply follow these steps:
1) Make sure you have enough free memory:
Open the usual apps you use (i.e. Visual Studio, Outlook, etc) and check how much free memory you have (Task Manager -> Performance -> Physical Memory -> Available).
So, let’s say you have 500MB free and your total memory physical memory is 2GB (Task Manager -> Performance -> Physical Memory -> Total). The total I’d recommend allocating for your virtual drive would be half of your free memory, or 250MB.
If you’re short on free memory, try running some cleanup tools like TuneUp Utilities (very good, but paid) or CCleaner (free). Besides that, you can always check what services are running and stop/disable the ones you really don’t need (this is a delicate step, be careful not to stop essential services – use Google to find out what’s essential and what’s not).
2) Install RamDisk
I’m using a free implementation that can be found here. You can follow these steps for a details explanation of this tool and installation instructions.
Make sure you install it and create a drive letter (i.e. “R:”) with the disk size amount calculated in the previous step. If you over-allocate it, your Windows will run out of memory and the whole purpose of this idea will be worthless.
3) Change your default “Temporary ASP.NET Files” folder to your new ram-based drive
Here you have two options. You can do this only for a specific site or for all projects running on your computer. If you have too many sites you may run out of disk space in your ramdisk, so choose your option wisely
3.1) Configuration for a specific website (local settings):
Change your site’s web.config “compilation” property to specify the new path. Below is an example that assumes “R:\ASP_NET_TempFiles\” as the new ram-based folder location:
<system.web>
....
<compilation debug="true" tempDirectory="R:\ASP_NET_TempFiles\">
....
</compilation>
....
</system.web>
3.2) Configuration for all ASP.net websites (global settings):
To implement this globally all you need to do is change your global web.config (which is usually located somewhere like this C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config)and adjust the compilation properties the same way the local settings (previous example):
<system.web>
....
<compilation debug="true" tempDirectory="R:\ASP_NET_TempFiles\">
....
</compilation>
....
</system.web>
And your done!
Two last tips I can give you is to keep an eye on the usage of your ramdisk folder. If it get’s full, you’ll have to manually delete some old temporary files. The second tip is to watch how your free memory, if it gets too close to it’s total it might indicate the you either have too much programs running or you might have to reduce your ramdisk size.
Happy speed building!