1 / 31

ASP.NET OPTIMIZATION

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

mansour
Download Presentation

ASP.NET OPTIMIZATION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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/StringBuilderEx.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/OptionStrictEx.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 <compilation> • 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 • 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 <asp:datagrid EnableViewState="false“ … /> • per page <%@ Page EnableViewState="false" %> • per usercontrol <%@ Control EnableViewState="false" %>

  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 • <%@ Page EnableSessionState="false" %> • ReadOnly • web.config file <sessionstate mode="off" />

  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 &= "<li>" & 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/173.aspx http://dotnetjunkies.com/WebLog/wayfarer/archive/2004/09/30/27318.aspx

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

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

More Related