ASP.NET OPTIMIZATION
Why Optimize? $$$ Whether you build applications for customers or not, enhanced applications save money.
Optimize Your Web Applications Improve your code Research strategies, methods, techniques Revisit old code Monitor your app Out-of-Box Third party Create your own
String Manipulation Use String Builders for modifying strings Mutable Value- can be modified appending removing replacing inserting characters More than three changes Ex.aspx
Server.Transfer HttpServerUtility.Transfer Parameters Path –URL as string preserveForm True- preserves QueryString and Form collections False(default)- clears QueryString and Form collections Terminates execution of the current page Begins execution of a new page Use when redirecting to another page within same application Avoids needless client-side redirection
Option Strict & Option Explicit For Visual Basic, VBScript and JScript Late binding expensive performance-wise Option Explicit forces you to declare your variables/objects before using them set to “On” by default Option Strict requires you to explicitly declare datatype conversions by disallowing late binding
Option Strict & Option Explicit Project Properties- turn them “On” In Page or Control Directive ‘ ’ Strict="true" Result- faster execution StrictEx.aspx
Avoid Exceptions Exceptions cause performance to suffer Avoid relying on exceptions in your code Anticipate exceptions checking for null check for specific values before applying math operations
Debug Mode Disable debug mode before you deploy a release application or conduct performance measurements Web.config Attribute- debug Option true- Specifies compilation of debug binaries false- Specifies compilation of retail binaries
Debug Mode Visual Studio When building change ddl Debug Release Examples.dll size From 380kb to 364kb From 412kb to 392kb
Data Access Open fewest possible connections (connection pooling) Data Access Layer- between Business Services and Data Services Data Access Make use of automatic pooling automatic transaction handling
Data Access Data Access Method SQL Server-based data access method provided by the.NET Framework Recommended for high performance Stored Procedures Additional performance boost Instead of ad-hoc queries
Data Access Advantages to Stored Procedures Database operations Can be encapsulated in a single command Are optimized for best performance Provides additional security ADO.NET Command object Explicitly defines stored procedure parameters Access output parameters and return values
Data Access Execute Scalar- value of the first column of the first row of the result set Retrieves a single value Examples- values returned by an aggregate function Count ( * ) Sum ( Field ) Avg ( Field )
Data Access SqlDataReader- forward-only data stream higher performance than the DataSet class Tabular Data Stream ( TDS ) protocol IEnumerable interface Instead of While Reader.Read() Databind()
ViewState Enabled by default To disable set MaintainState property to false per control per page per usercontrol
ViewState Light Control Group Label TextBox Button LinkButton ImageButton CheckBox RadioButton HyperLink
ViewState Datagrid DataList Repeater CheckBoxList
Session State Disable when not using per-user session state Configure Session State ReadOnly web.config file
Session State Provider In-process session state Out-of-process session state as a Windows Service Out-of-process session state in a SQL Server database
Server Round Trips Avoid unnecessary round trips to the server retrieving data storing data Use HTML controls instead of ASP.NET server controls Use appropriate postback event handling Use client side script for data manipulation
Cache Avoids overhead of retrieving information from resources outside the application. Stores page output or application data Stores data on the client or on the server
Cache Output caching, which caches the dynamic response generated by a request. Fragment caching, which caches portions of a response generated by a request. Data caching, which allows developers to programmatically retain arbitrary data across requests
Cache Sub Page_Load Dim objItem As DictionaryEntry For each objItem in Cache lblContents.Text &= " " & objItem.Key lblContents.Text &= "=" & objItem.Value.ToString Next End Sub
String Manipulation us/cpref/html/frlrfsystemtextstringbuilderclasstopic.asp us/cpref/html/frlrfsystemstringclasstopic.asp
Server.Transfer us/cpref/html/frlrfsystemwebhttpserverutilityclasstransfertopic.asp us/cpref/html/frlrfSystemWebHttpServerUtilityClassTransferTopic.asp
Option Strict & Option Explicit webapps/developinghigh- performanceaspnetapplications.aspx /10/07/173.aspx
Avoid Exceptions webapps/developinghigh- performanceaspnetapplications.aspx
Debug en- us/vsdebug/html/vxtskdebugmodeinaspnetapplications.asp compilationsection.aspx 73.aspx 09/30/27318.aspx
Data Access ng-a-Robust-and-Highly-Scalable- Distributed-Architecture-using-VB-NET/1
ViewState viewstate