F.ASP.Net Performance Optimization
Overview
Summary
ASP.Net performance are driven by multiple factors including hardware , security , Application Pool configuration session state , view state, Deployment architecture etc.
In order to get achieve optimal performance we need to carefully understand each factor and optimize them as required
Videos Tutorial
ASP.Net Performance Recommendations
Page and Server Control Processing
Avoid unnecessary round trips to the server , use Client Callbacks Without Postbacks in ASP.NET Web Pages.
Use the Page object's IsPostBack property to avoid performing unnecessary processing on a round trip
Save server control view state only when necessary
Leave buffering on unless you have a specific reason to turn it off
Use the Transfer method of the Server object or cross-page posting to redirect between ASP.NET pages in the same application
State Management
Disable session state when you are not using it because it causes memory overhead and also request serialization can degrade performance in several scenario.
Choose the right session-state provider for your application needs
Prefer turning of View State and global level and enable only for the controls or pages that really need it.
Prefer not to store any large object in view state
Data Access
Use SQL Server and stored procedures for data access
Use the SqlDataReader class for a fast forward-only data cursor
Cache data and page output whenever possible
Use SQL cache dependency appropriately
Use data source paging and sorting rather the UI (user interface) paging and sorting
Balance the security benefit of event validation with its performance cost
Avoid using view state encryption unless necessary
Use SqlDataSource caching, sorting, and filtering when ever possible in case of small data sets
Prefer Server side paging and sorting for large data sizes
By default SQL Data Sources like ADO do paging and sorting at client side that degrade performance in case of large data set.
Consider EF code first and ASP.NET 4.5 model binding
Prefer QueryableDataSource or ObjectDataSource over SqlDataSource as they support server side paging and sorting.
Application Configuration
Consider precompiling
Run Web applications out-of-process on Internet Information Services 5.0
Recycle processes periodically
Adjust the number of threads per worker process for your application if necessary
For applications that rely extensively on external resources, consider enabling Web gardening on multiprocessor computers
Disable debug mode
Enable authentication only for applications that need it
Configure your application to the appropriate request and response encoding settings
Consider disabling AutoEventWireup for your application
Remove unused modules from the request-processing pipeline.
Remove any empty event handler from application particularly from global.assx
Turn off runAllManagedModulesForAllRequests (RAMMFAR) whenever possible to prevent static content being accessed via ASP.Net pipeline but be careful of authentication requirements Read More...
Coding Practices
Do not rely on exceptions in your code Exceptions can cause performance to suffer significantly so try detecting code condition that could cause an exception
Rewrite call-intensive COM components in managed code
Avoid single-threaded apartment (STA) COM components
Use Async/Await to increases efficient use of thread pool resources
Application Architecture
Prefer WebSocket for long running request because ASP.Net has 30K of overhead per request and web-socket has 10K or else prefer using SignalR
Use App Suspension feature of 4.5 to increase server resource utilization.
Never writes to files under c:\inetpub\wwwroot because it will overload FileSystemWatcher component that mainly keeps track of changes in application folder such as web config updated.
Prefer using 32-bit vs. 64-bit processes and then creates a web-garden this will reduce memory overhead in case of large object graphs.
Deployment Structure
Keep ASPX files in minimum number of folders because it decreases compilation overhead.
Consider enabling CDNs on ScriptManager
ASP.Net Performance Monitoring
ASP.Net Application Profiling
How to FAQ
How to: View the ASP.NET Performance Counters Available on Your Computer
Related Concepts
Web Form
Web Garden
Session State
View State
Further Discussion
Relates Tools
Glimpse: Real time diagnostics it is actually friendly version of VS intellitrace
References