asp.net optimization (ii.)

Source: Internet
Author: User
Tags numeric value advantage
Asp.net| optimization
      1. Don't rely on exceptions in your code: Exceptions are very expensive and should rarely in occur code. You are should never use exceptions as a way to the normal program flow. If it is possible into detect in the code a condition that would cause a exception and you should does that instead the waiting to CA TCH the exception before handling that condition. Common scenarios include checking for null, assigning to a string that'll be parsed into a numeric value, or checking fo R specific values before applying math operations. For example:

      1. Consider changing this:try {result = 100/num;} catch (Exception e) {result = 0;} To This:if (num!= 0) result = 100/num;else result = 0;
    ' consider changing this:try result = 100/numcatch (e as Exception) result = 0End try//to this:if not (num = 0) re Sult = 100/numelse result = 0End If
    Consider changing this:try {result = 100/num;} catch (e:exception) {result = 0;} To This:if (num!= 0) result = 100/num;else result = 0;
    C # VB JScript
    1. Use early binding in Visual Basic or JScript code: One of the advantages of Visual Basic, VBScript, and JScript I s their typeless nature. Variables can is created simply by using them and need no explicit type declaration. When assigning from one type to another, conversions are performed automatically, as. This can are both an advantage and a disadvantage, since late binding are a very expensive convenience in terms of Performan Ce.
    2. The Visual Basic language now supports Type-safe programming through the use of a special Option Strict directive. For backward compatibility, ASP.net does not enable Option Strict by default. However, for optimal perfomance, your should enable Option Strict for your pages by using a Strict attrib Ute on the page or control directive:
    3. <%@ Page language= "VB" strict= "true"%><%dim Bdim C as String ' This causes a compiler error:a = ' Hello ' ' This Cau Ses a compiler error:b = "World" ' this does NOT:C = '!!!!!! ' But this does:c = 0%>
    4. JScript also supports typeless programming, though it offers no compiler directive to force early. A variable is late-bound if:
    5. It is declared explicitly as a object.
      • It is a field of the A class with no type declaration.
      • It is a private Function/method member with no explicit type declaration and the type cannot to be inferred to.
    1. The last distinction is complicated. The JScript compiler optimizes if it can figure out of the type, based on how a variable is used. In the following example, the variable A are early-bound but the variable B is late-bound:
    2. var a;var B; A = "Hello"; B = "World"; B = 0;
    3. For the best performance, declare your JScript variables as has a type. For example, "Var a:string".
    4. Port call-intensive COM components to managed code: the. NET Framework provides a remarkably easy way to interoperate with traditional COM components. The benefit is this you can take advantage of the the new platform while preserving the your code. However, there are some circumstances in which the performance cost of keeping your old components is greater than the Cos T to migrate your components to managed code. The Every situation is unique, and the best way to decide what needs to being changed to measure site. In general, however, the performance impact of COM interoperability are proportional to the number of function calls made O R The amount of data marshaled from unmanaged to managed code. A component that requires a high volume of calls to interact with it are called "chatty," due to the number of Communicatio NS between layers. You are should consider porting such components to fully managed code to benefit from the performance gains provided by the. N ET platform. Alternatively, you might consider redesigning your ComponenT to require fewer calls or to marshal more data at once.
    5. Use SQL stored procedures for data access: "All" the data access methods provided by the. NET Framework, Sql-bas Ed data access is the best choice for building scalable Web applications with the best performance. When using the managed SQL provider, you can get a additional performance boost by using compiled stored procedures Inste ad hoc queries. For a example of using SQL stored procedures, refer to the Server-side Data Access section of this tutorial.
    6. Use SqlDataReader for a fast-forward, read-only data cursor : A SqlDataReader object provides a forward, Read-only cursor over the data retrieved from SQL database. Because SqlDataReader uses tabular data Stream (TDS) packets to read data directly. A database connection, it p Rovides better performance than using a DataSet , if you can use this for your scenario. Because SqlDataReader supports the IEnumerable interface, you can even bind server controls, as. For a example of using SqlDataReader , the Server-side Data Access section of this tutorial.
    7. Cache data and output wherever possible : the ASP.net programming model provides a simple mechanism for caching Page output or data when it does is not need to is dynamically computed for every request. Can design your pages with caching in mind to optimize those places in your application this you expect to have the MO St Traffic. More than any feature of the. NET Framework, the appropriate use of caching can enhance the performance of your site, some Magnitude or more. For more information about the "Use caching," The Cache Services section of this tutorial.
    8. enable Web Gardening for multiprocessor computers: The asp.net process model helps Enable scalability on Multipro Cessor machines by distributing the work to several processes, one for each CPU, each with processor affinity set to its C Pu. The technique is called Web gardening, and can dramatically improve the performance of some applications. To learn you to enable Web gardening, refer to the Using the "Process Model section."
    9. Don't forget to disable Debug mode: The <compilation> section in asp.net configuration controls W Hether an application are compiled in Debug mode, or not. Debug mode degrades performance significantly. Always Remember to disable Debug mode before you deploy a production application or measure performance. For more information about Debug mode, refer to the section entitled The SDK Debugger.


    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.