Tips and Tricks on how to improve MVC Application Performance

In this post we will cover a few tips and tricks to improve ASP.NET MVC Application Performance.

Run in Release mode

Make sure your production application always runs in release mode in the web.config


or change this in the machine.config on the production servers


    
          
    

Only use the View Engines that you require

protected void Application_Start() 
{ 
	ViewEngines.Engines.Clear(); 
	ViewEngines.Engines.Add(new RazorViewEngine()); 
}

Use the CachedDataAnnotationsModelMetadataProvider

ModelMetadataProviders.Current = new CachedDataAnnotationsModelMetadataProvider();

Avoid passing null models to views

Because a NullReferenceException will be thrown when the expression gets evaluated, which .NET then has to handle gracefully.

// BAD
public ActionResult Profile() 
{ 
	return View(); 
}
// GOOD
public ActionResult Profile() 
{ 
	return View(new Profile()); 
}

Use OutputCacheAttribute when appropriate

For content that does not change often, use the OutputCacheAttribute to save unnecessary and action executions.

[OutputCache(VaryByParam = "none", Duration = 3600)]
public ActionResult Categories() 
{ 
	return View(new Categories()); 
}

Use HTTP Compression

 


Remove unused HTTP Modules

If you run into any problems after removing them, try adding them back in.


      
      
      
      

Flush your HTML as soon as it is generated


Turn off Tracing


     
          
     

Remove HTTP Headers

This is more of a security thing


    


 
  
 

Uninstall the URL Rewrite module if not required

This saves CPU cycles used to check the server variable for each request.

Go to "Add or Remove Programs" and find "Microsoft URL Rewrite Module" and select uninstall. 

Don’t write rubbish code

Just don’t.



Comments

  1. mathi June 21st

    Comment Arrow

    Thanks. Its really useful.


  2. Darren August 28th

    Comment Arrow

    I actually benefit from your article.Thanks.


  3. pardha August 28th

    Comment Arrow

    nice work


Add Yours

  • Author Avatar

    YOU


Comment Arrow




About Author

Robert

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning hands down.