ASP.NET OPTIMIZATION - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

ASP.NET OPTIMIZATION

Description:

Use String Builders for modifying strings. Mutable Value ... For Visual Basic, VBScript and JScript. Late binding. expensive performance-wise. Option Explicit ... – PowerPoint PPT presentation

Number of Views:116
Avg rating:3.0/5.0
Slides: 32
Provided by: tcy7
Category:

less

Transcript and Presenter's Notes

Title: ASP.NET OPTIMIZATION


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 lt_at_ gt
  • Strict"true"
  • Result- faster execution
  • http//www.varay.com/Optimization/OptionStrictEx.a
    spx

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 ltcompilationgt
  • 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
  • ltaspdatagrid EnableViewState"false /gt
  • per page
  • lt_at_ Page EnableViewState"false" gt
  • per usercontrol
  • lt_at_ Control EnableViewState"false" gt

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
  • lt_at_ Page EnableSessionState"false" gt
  • ReadOnly
  • web.config file ltsessionstate mode"off" /gt

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 "ltligt" objItem.Key
  • lblContents.Text "" objItem.Value.ToStri
    ng
  • Next
  • End Sub
  • http//www.superexpert.com/default.aspx?id371

25
String Manipulation
  • http//robz.homedns.org8080/blog/archive/2004/10/
    07/173.aspx
  • http//msdn.microsoft.com/library/default.asp?url
    /library/en-us/cpref/html/frlrfsystemtextstringbui
    lderclasstopic.asp
  • http//msdn.microsoft.com/library/default.asp?url
    /library/en-us/cpref/html/frlrfsystemstringclassto
    pic.asp

26
Server.Transfer
  • http//msdn.microsoft.com/library/default.asp?url
    /library/en-us/cpref/html/frlrfsystemwebhttpserver
    utilityclasstransfertopic.asp
  • http//msdn.microsoft.com/library/default.asp?url
    /library/en-us/cpref/html/frlrfSystemWebHttpServer
    UtilityClassTransferTopic.asp

27
Option Strict Option Explicit
  • http//authors.aspalliance.com/aspxtreme/webapps/d
    evelopinghigh-performanceaspnetapplications.aspx
  • http//robz.homedns.org8080/blog/archive/2004/10/
    07/173.aspx

28
Avoid Exceptions
  • http//authors.aspalliance.com/aspxtreme/webapps/d
    evelopinghigh-performanceaspnetapplications.aspx

29
Debug
  • http//msdn.microsoft.com/library/default.asp?url
    /library/en-us/vsdebug/html/vxtskdebugmodeinaspnet
    applications.asp
  • http//authors.aspalliance.com/aspxtreme/aspnet/sy
    ntax/compilationsection.aspx
  • http//robz.homedns.org8080/blog/archive/2004/10/
    07/173.aspx
  • http//dotnetjunkies.com/WebLog/wayfarer/archive/2
    004/09/30/27318.aspx

30
Data Access
  • http//www.aspfree.com/c/a/VB.NET/Building-a-Robus
    t-and-Highly-Scalable-Distributed-Architecture-usi
    ng-VB-NET/1

31
ViewState
  • http//webreference.com/programming/asp/viewstate
Write a Comment
User Comments (0)
About PowerShow.com