473,498 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Internet Explorer vs. Firefox javascript array performance

I am trying to complete a javascript application and am having problems
with code similar to that show below.

Much testing has shown that Firefox finishes the code shown in around
0.25 secs but Internet Explorer 6 takes a massive 3.5 secs! Internet
Explorer 7 gets it down to around 2 seconds - but that's still 8 times
slower than Firefox and way unacceptable for my userbase.

Looking through the newsgroups there is some discussion around the
differences between the way the two browsers handle arrays - but a
performance differential such as this is just unbelievably dismal.

Unfortunately I need to continue to use arrays of objects and have to
support the Internet Explorer client base. I have already added
specification of the array size and also removed the use of array
"push"ing - flattening the array is not really an option.

Has anyone got experience of this and have any suggestions for me to
try out?

Many thanks,

// JavaScript Document

var ItemArray = new Array(10000);

now = new Date;
start = now.getTime();

for (Count=0; Count<10000; Count++)
ItemArray[Count] = new Item("Field1", "Field2", "Field3");

now = new Date;
end = now.getTime();

alert("Test took " + ((end - start) / 1000) + " seconds");

function Item(Field1, Field2, Field3)
{
this.Field = new Array(3);

this.Field[0] = Field1;
this.Field[1] = Field2;
this.Field[2] = Field3;

this.Flags = new Array(2);

this.Flags[0] = true;
this.Flags[1] = false;
}

Oct 10 '06 #1
3 9822

go****@grepit.com wrote:
I am trying to complete a javascript application and am having problems
with code similar to that show below.

Much testing has shown that Firefox finishes the code shown in around
0.25 secs but Internet Explorer 6 takes a massive 3.5 secs! Internet
Explorer 7 gets it down to around 2 seconds - but that's still 8 times
slower than Firefox and way unacceptable for my userbase.

Looking through the newsgroups there is some discussion around the
differences between the way the two browsers handle arrays - but a
performance differential such as this is just unbelievably dismal.

Unfortunately I need to continue to use arrays of objects and have to
support the Internet Explorer client base. I have already added
specification of the array size and also removed the use of array
"push"ing - flattening the array is not really an option.
Did that make any difference?

Has anyone got experience of this and have any suggestions for me to
try out?
For me, the following is marginally faster, but I don't think it will
give you the kind of gains you are after:

var ItemArray = [];
var start = new Date().getTime();
var i = 5000;
while (i--) {
ItemArray[i] = new Item("Field1", "Field2", "Field3");
}

var end = new Date().getTime();

alert("Test took " + ((end - start) / 1000) + " seconds");

function Item(Field1, Field2, Field3)
{
this.Field = [Field1, Field2, Field3];
this.Flags = [true, false];
}
--
Rob

Oct 10 '06 #2
Thanks for your suggestions.

You are right in that the suggestions will improve performance, but not
give the order of magnitude I need to find.

I found that I could roughly halve the Internet Explorer 6 processing
time by not having an array of objects, but just using a 2 dimensional
array.

One of the downsides to this approach, is that I lost the object
structure which made the code easy to understand through being able to
reference "Item[n].Field[n]" and "Item[n].Flags[n]" - ending up with
"Item[n][m]" type references.

I guess I am just amazed at the IE/Firefox performance diffential. One
thought I has was that maybe Microsoft are more focused on getting
solutions built with server-side technology, rather than building a
browser that can handle the type of processing - that's where the
revenue is I guess ...

Oct 10 '06 #3
VK
So Gecko does cache dispid's... No wonder with their JavaScript engine
dependance for the entire browser - yet it's nice to know for sure
without digging in C-sources.

In application to IE IDispatcher doesn't cache dispid's, other words
every time it needs a reference to an object/member it takes the string
name ("Item" in your case) and searches for the memory address in the
names table. Every single of 10,000 times...

So you can improve the performance by not forcing IDispatcher to go for
external references. It seems slow down Firefox for just a little bit
(I don't know why) but on my test machines it shows 150% performance
gain for IE:

<script type="text/javascript">
var ItemArray1 = new Array(10000);

now = new Date;
start = now.getTime();

for (Count=0; Count<10000; Count++) {
ItemArray1[Count] = {
'Field' : [0,1,2]
, 'Flags' : [true, false]
};
}

now = new Date;
end = now.getTime();

alert("Test took " + ((end - start) / 1000) + " seconds");
</script>

P.S. "Second's fractions hunters" :-) : please do not take it as a
stimulus to drop OOP immediately on IE :-) But for extrim cases
(10,000...100,000... objects to create in one loop) that can be
something to takes into consideration.

Oct 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8510
by: Jason Keirstead | last post by:
Is there a way I can add a setter/getter to the HTMLElement prototype in internet explorer? This, for example, works fine in Mozilla: HTMLElement.prototype.__defineSetter__("foobar", function...
11
1733
by: dhplank | last post by:
Hello everyone, I've developed a calendar program in javascript, and up until now I've done most of my testing using Mozilla and Firefox. Everything works fine, but when I try to use Internet...
11
1996
by: GHUM | last post by:
Hello, I created some rather complex Intranet Application, using lots of JavaScript, DOM-Maninpulation and XMLHTTPRequest communication. I developed on FireFox, with the excellent firebug ......
5
1691
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to...
1
2328
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to...
26
2234
by: Prisoner at War | last post by:
Hi, All: I have a JavaScript search engine that always causes MSIE 7 to do a top-of-page security "warning" (that top-of-page-bar, and not an "alert" )...but other websites' JavaScripts do not...
1
4808
by: avpkills2002 | last post by:
I seem to be getting this weird problem in Internet explorer. I have written a code for parsing a XML file and displaying the output. The code works perfectly fine with ffx(Firefox).However is not...
2
3126
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.