|
|
Way to improve performance when using JavaScript String class in an Ajax environment
|
03/25/2006, By Ajax Impact News
|
Over Captian's blog there is an intresting analysis regarding the use of JavaScript String class, that will be usefull when developer code in an Ajax environment. He have done the comparision in three way on use of string.
After analysis it was found that the difference is amazing, the code executes in 90 milliseconds, almost 30 times as fast as the original code!
He writes " About 6 or 7 years ago when I was doing Ajax like development before it was the fashionable thing to do (and everyone told me I was nuts) I ran into performance problems on the client due to the large number of string concatenations that were required to render the data to the screen.
Unfortunately JavaScript does not offer the same powerful classes like Java's StringBuffer and dotNet's StringBuilder so I had to be a bit creative and come up with a workaround.
So what is the magic ingredient? The StringBuilder class encapsulates a simple JavaScript array. Every time a string is added to this array the size of the array is increased by 1, a relatively fast operation. The string is not even copied but a reference to the string is added to the array, which again is a very fast operation.
When we need the full string (the toString() method) then we let the system do all the work by calling arrayName.join(""), which takes about 10 milliseconds.
This code is used on several major e-commerce sites and has made the difference between being sluggish and being very fast. The difference is even more apparent on slower systems.
Watch the complete demo examples here as well as Download complete code for this example.
Want to read more... Click here
|
Rate this Ajax News
Rating: 0.0 out of votes cast
| |
|
|
| |
|
|
|
|
|
|
|
|