Ways to improve Ajax performance

Source: Internet
Author: User
Tags constructor contains end log return string
first, the introduction

In Web Forms, we use the AJAXTo invoke the server-side method from the client (through JavaScript), while the AJAXInternally, the XMLHttpRequest call is made. I tested some AJAX functions that were implemented in different ways. In addition, I monitored the performance and lifecycle of Ajax calls. As a result, I found that in Web Forms I use AJAXThere are some serious problems. However, I have also found a solution to these problems. In this article, I just want to analyze this problem with you and the corresponding solution.

   Ii. performance issues encountered while using AJAX

For each Ajax call, we're going to create an instance of the class that contains the Ajax method. In addition, if we use the New keyword at the class level, we also create instances for the fields, attributes, and other class-level variables.

   III. Implementation of the programme

I created a project that contains two Web forms: WebForm1.aspx and Webform2.aspx, and a class Student.vb. Both parts of the Code-behind page use a AJAXfunction GetData () and a student type of public variable. With the help of the Mxlogger class, I recorded the execution process for each phase.

Note: Webform2.aspx's Ajax function GetData () is shared, and in WebForm1 it is not shared.

' Student.vb
Public Class Student
Sub New ()
Mxlogger.addlog ("from Student.constructor")
End Sub
Dim _name as String
Public Property Name () as String
Get
return _name
End Get
Set (ByVal Value as String)
_name = Value
End Set
End Property
End Class

' WebForm1.aspx.vb
Public Class WebForm1
Public Student as New Student
Sub New ()
Mxlogger.addlog ("from Webform1.constructor")
End Sub
_
Public Function GetData () as String
Mxlogger.addlog ("from WebForm1.Ajax.getData ()")
Return "I m a Non Shared Function"
End Function
End Class
' WebForm2.aspx.vb
Public Class WebForm2
Public Student as New Student
Sub New ()
Mxlogger.addlog ("from Webform2.constructor")
End Sub
_
Public Shared Function GetData () as String
Mxlogger.addlog ("from WebForm2.Ajax.getData ()")
Return "I m a Shared Function"
End Function
End Class

   Iv. Testing Applications

· Test Case 1:

Run WebForm1.aspx and invoke the GetData () Ajax function three times from JavaScript.

· Test Case 2:

Run Webform2.aspx and invoke the GetData () Ajax function three times from JavaScript.

For the test cases above, I get the following log output data:

Note that for the purposes of interpretation, I have manually added some journal lines
LOG for the Test Case 1: (Non Ajax Shared Function)

-------while Loading the Page--------
5/9/2006 10:37:29 Am>>from Student.constructor
5/9/2006 10:37:29 Am>>from Webform1.constructor
5/9/2006 10:37:29 am>>from WebForm1.Ajax.getData ()
-------the GetData ()--------
5/9/2006 10:37:29 Am>>from Student.constructor
5/9/2006 10:37:29 Am>>from Webform1.constructor
5/9/2006 10:37:29 am>>from WebForm1.Ajax.getData ()
-------Second call for GetData ()--------
5/9/2006 10:37:29 Am>>from Student.constructor
5/9/2006 10:37:29 Am>>from Webform1.constructor
5/9/2006 10:37:29 am>>from WebForm1.Ajax.getData ()
-------Third call for GetData ()--------
5/9/2006 10:37:30 Am>>from Student.constructor
5/9/2006 10:37:30 Am>>from Webform1.constructor
5/9/2006 10:37:30 am>>from WebForm1.Ajax.getData ()

LOG for the Test Case 2: (Shared Ajax Function)

-------while Loading the Page--------
5/9/2006 10:37:09 Am>>from Student.constructor
5/9/2006 10:37:09 Am>>from Webform2.constructor
5/9/2006 10:37:09 am>>from WebForm2.Ajax.getData ()
-------the GetData ()--------
5/9/2006 10:38:11 am>>from WebForm2.Ajax.getData ()
-------Second call for GetData ()--------
5/9/2006 10:38:11 am>>from WebForm2.Ajax.getData ()
-------Third call for GetData ()--------
5/9/2006 10:38:11 am>>from WebForm2.Ajax.getData ()

We can see that in the log output data above, for test Case 1, we can see more log data from the Webform1 and student constructors.

   v. Conclusion

My suggestion is that, at all possible places, we should use the AJAXmethod so that it does not create more Web Form instances and class-level fields. In this way, we can reduce the number of calls to finalize () from the GC.

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.