Speed optimization in ASP .Net web applications

Following are some of the points, that need to be kept in mind while developing a web based application in ASP .Net:

  • First and most popular way to speed up a web application is to use caching.
  • Disable ViewState property of any control that does not need view state.
  • Put all code of page_load under if(!isPostback) other than codes that specifically need to be loaded on every page load.
  • Use javascript in a separate file and embed them rather than putting it into the same file. Also remove any unused javascripts from file.
  • Do not throw an exception unless doing so is necessary.
  • Disable session state, when not using it.
  • Use StringBuilder for large string operations.
  • In case of using web services use asynchronous call to web services. Also wait for end of the call before the page is fully loaded.
  • Use Threading when downloading huge amount of data.

Apart from the above points, the most important part is the Data Access part of a web application, which reduces the performance of an application. Every time we go for some query of data or other data accesses from database, we reduce the speed of the application. So, following points should be taken care of while establishing a data connection:

  • Use DataReader: If you’re just consuming rather than caching data, and operate in a forward-only, read-only way, the data reader represents a better option.
  • Use Caching of Data: However all data cannot be cached or in some cases when data changes every moment caching may not be efficient, still retrieving cached data is faster than retrieving it from database. Caching should be used very carefully because, the longer time you cache a value, the more stale it becomes.
  • Use useful properties of SQLDataSource: Instead of writing a query that includes the “Where”, or “Sort By” clauses use the caching, filtering and sorting properties of the SQLDataSourse provider.
  • Use Stored Procedures: Stored Procedures should be used whenever it is possible, as SQL server builds and stores execution plans for procedures.
  • Use Paging: In case of large data handling, one should use paging to make it efficient and fast. There are two types of paging available in ASP .Net: default paging and custom paging. Custom Paging is better among the two, as it requests less data from database than default paging.

Leave a Reply

Your email address will not be published. Required fields are marked *