JScript Memory Help, please MS MVP Respond

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Here is the problem


"Jscript incrementally becomes slow with large number of objects especially
custom objects."
When custom objects are created in memory, as the number of objects increase
following happens,

1) Time to create new object incrementally increases.

This means it would take more time to create objects as you have more number
of objects existing in memory, even though object have nothing to do with
each other.

2) Time to access objects also incrementally increases.

This means scripts in page will appear to be slow in doing everything when
lot of Jscript objects exists on the page.

To demonstrate this I have created simple test on the page
http://www.geocities.com/arvindsagarwal/test.htm

In the above page, initially it records result 1 & 2, where objects are
created and destroyed immediately; it takes 270ms & 240ms on my machine to
create 10,000 objects.

Sample code for step 1 & 2
pctr=10000;

i=pctr;

do
{
var o=new obj3(); //objects are created and destroyed since
o is automatically destroyed with every loop
o.Method1();
}while( --i);

Now, to demonstrate behavior of Jscript where it goes slower when objects
are retained in memory, step 3 actually creates 10,000 objects and puts them
in an array. So this means now 10,000 objects are existing in memory.

Sample code for step 3
i=pctr;
var cols=new Array();
do
{
var o=new obj3();
cols.push(o); //objects are now added to collection and not
destroyed
o.Method1();
}while( --i);

Now same code which is used for step 1 & 2, which took 270 & 240ms, takes
721ms to create 10,000 objects in step 4 & 5 (in this case also objects are
immediately destroyed upon creation). So it clearly shows that just because
there is an array of 10,000 objects the creation time of object has gone by
2.6 times. This is just a simple case in reality objects would be very
complex and large and things can become slower if anything serious is done
with Jscript and IE.

Sample code for step 4 & 5 (note this is same as 1 & 2)
pctr=10000;
i=pctr;


do
{
var o=new obj3(); //objects are created and destroyed since
o is automatically destroyed with every loop
o.Method1(); //Just because 10,000 objects exists in an
array, the same code takes 2.6 times more to execute
}while( --i);

Although it might not look that this issue will generally cause any
performance issue, it can have serious implications on the Jscript based work
done on IE, generally it is blamed on large number of document objects but
actually issue is with Jscript itself. Jscript team feels that this is
related to bad garbage collection implementation in IE, but no committement
on if they will fix it. Same thing works very well on Netscape 7.2 and
Firefox 1.0 and there is no extra time taken in creation or accessing of
object even if large number of objects exists in memory. Infect to my
surprise in Firefox and Netscape both creation of objects was much faster,
for step 1 & 2 it took 60 & 70ms and for step 4 & 5 it still takes 60 & 80ms.

---


.



Relevant Pages

  • Re: How many functions can IE handle?
    ... has a web client architecture completely written in JScript. ... >> How is memory handled within IE in respect to Jscript? ... or the browser just crashes. ...
    (microsoft.public.scripting.jscript)
  • Re: JScript Memory Leak
    ... Why are you using eval to evaluate the regular expressions? ... just use the Regex class in the System.Text.RegularExpressions namespace? ... seems to handle memory the most ... jscript eval}, JScript will leak memory and grow the virtual memory ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: JScript Memory Help, please MS MVP Respond
    ... For a better, faster response, post this to one of the Jscript newsgroup, if you haven't already: ... When custom objects are created in memory, as the number of objects increase ... in an array. ... immediately destroyed upon creation). ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • JScript Memory Allocation - HELP please respond MS MSVP
    ... "Jscript incrementally becomes slow with large number of objects especially ... When custom objects are created in memory, as the number of objects increase ... immediately destroyed upon creation). ...
    (microsoft.public.scripting.jscript)
  • JScript Memory Allocation - HELP please respond MS MSVP
    ... "Jscript incrementally becomes slow with large number of objects especially ... When custom objects are created in memory, as the number of objects increase ... immediately destroyed upon creation). ...
    (microsoft.public.scripting.jscript)