Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP.NET OPTIMIZATION. Why Optimize? $$$ Whether you build applications for customers or not, enhanced applications save money.

Similar presentations


Presentation on theme: "ASP.NET OPTIMIZATION. Why Optimize? $$$ Whether you build applications for customers or not, enhanced applications save money."— Presentation transcript:

1 ASP.NET OPTIMIZATION

2 Why Optimize? $$$ Whether you build applications for customers or not, enhanced applications save money.

3 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

4 String Manipulation Use String Builders for modifying strings Mutable Value- can be modified appending removing replacing inserting characters More than three changes http://www.varay.com/Optimization/StringBuilder Ex.aspx

5 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

6 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

7 Option Strict & Option Explicit Project Properties- turn them “On” In Page or Control Directive ‘ ’ Strict="true" Result- faster execution http://www.varay.com/Optimization/Option StrictEx.aspx

8 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

9 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

10 Debug Mode Visual Studio When building change ddl Debug Release Examples.dll size From 380kb to 364kb From 412kb to 392kb

11 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

12 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

13 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

14 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 )

15 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()

16 ViewState Enabled by default To disable set MaintainState property to false per control per page per usercontrol

17 ViewState Light Control Group Label TextBox Button LinkButton ImageButton CheckBox RadioButton HyperLink

18 ViewState Datagrid DataList Repeater CheckBoxList

19 Session State Disable when not using per-user session state Configure Session State ReadOnly web.config file

20 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

21 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

22 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

23 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

24 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 http://www.superexpert.com/default.aspx?id=371

25 String Manipulation http://robz.homedns.org:8080/blog/archive/2004/10/07/173.aspx http://msdn.microsoft.com/library/default.asp?url=/library/en- us/cpref/html/frlrfsystemtextstringbuilderclasstopic.asp http://msdn.microsoft.com/library/default.asp?url=/library/en- us/cpref/html/frlrfsystemstringclasstopic.asp

26 Server.Transfer http://msdn.microsoft.com/library/default.asp?url=/library/en- us/cpref/html/frlrfsystemwebhttpserverutilityclasstransfertopic.asp http://msdn.microsoft.com/library/default.asp?url=/library/en- us/cpref/html/frlrfSystemWebHttpServerUtilityClassTransferTopic.asp

27 Option Strict & Option Explicit http://authors.aspalliance.com/aspxtreme/ webapps/developinghigh- performanceaspnetapplications.aspx http://robz.homedns.org:8080/blog/archive/ 2004/10/07/173.aspx

28 Avoid Exceptions http://authors.aspalliance.com/aspxtreme/ webapps/developinghigh- performanceaspnetapplications.aspx

29 Debug http://msdn.microsoft.com/library/default.asp?url=/library/ en- us/vsdebug/html/vxtskdebugmodeinaspnetapplications.asp http://authors.aspalliance.com/aspxtreme/aspnet/syntax/ compilationsection.aspx http://robz.homedns.org:8080/blog/archive/2004/10/07/1 73.aspx http://dotnetjunkies.com/WebLog/wayfarer/archive/2004/ 09/30/27318.aspx

30 Data Access http://www.aspfree.com/c/a/VB.NET/Buildi ng-a-Robust-and-Highly-Scalable- Distributed-Architecture-using-VB-NET/1

31 ViewState http://webreference.com/programming/asp/ viewstate


Download ppt "ASP.NET OPTIMIZATION. Why Optimize? $$$ Whether you build applications for customers or not, enhanced applications save money."

Similar presentations


Ads by Google