Optimization techniques vary with the functionality in your application, so
here are some general tips when optimizing the performance of a web
application.
Monitor Performance
In order to assess the performance of your application, you need to take
objective benchmarks. If you run the Performance Monitor (perfmon.exe) on your
server, you can track CPU, Memory, and Disk utilization, as well as
measurements specific to ASP.NET and IIS, such as requests per second. Using
these tools will help you determine where performance problems lie.
Visual Studio.NET also comes with a new stress-testing tool, Microsoft
Application Center Test. Using this tool, you can record a browser session
while navigating through your site, or write your own custom scripts. Using
these scripts, you can simulate many concurrent connections to your web server,
and collect perfmon statistics. Although your application may work fine in
development, having a couple hundred simulatenous connections can introduce a
host of new problems.
Use SqlReader for Forward-Only Data
If you need data from a database and only need to loop through it, perhaps to
populate a select box, use a DataReader over a DataSet. The DataReader, such as
the SqlDataReader, does not store the data in memory like the dataset, and
offers much better performance in forward-only scenarios.
Consider Asynchronous calls and Remoting
If you have a component that takes a while to complete, consider calling it
asynchronously so the calling application can continue working, or using
Remoting to offload the load of that component to a dedicated server.
Utilize Caching
Implement caching for frequently accessed pages that do not change often to
enhance performance. See the section on Caching for
more information on how to implement output, fragment, and data caching.
Disable Session State
If you are not using Session State in your application, you should disable it
in the web.config file, or if certain pages do not use session state, then you
should set the Page directive's EnableSessionState attribute to "false" for
those pages.
Enable ViewState Only When Necessary
Storing the ViewState can take a noticeable amount of space, depending on the
complexity of your pages. If you do not need the postback behavior that the
viewstate provides, set the EnableViewState attribute equal to "false" for the
specific control or page. This can minimize the amount of HTML sent to the
client, improving download times and processing times on your server.
Compile in Release Mode
During development, you'll compile in Debug mode to get additional information
about errors, and to enable debugging. However, for your production
environment, be sure to compile and publish your code in the Release
configuration. This removes the overhead of the debug code.