User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Inefficient Javascript Causing Error in IE Page [1]  
OmarBadu
zidik
25067 Posts
user info
edit post

The following javascript causes IE to think the script is unresponsive when there is a large dataset - can anyone help in making this more efficient

as a side note chrome and firefox handle it just fine (at least with the datasets i've tried)

        var count = 0;
for (var i in control.nodeMap)
count++;
if (count == 0) {
for (i = 0; i < locationGroupTreeView.Data.length; i++) {
var node = locationGroupTreeView.Data[i];
control.nodeMap[node[3][0][1]] = locationGroupTreeView.findNodeById(node[3][0][1]);
var characters = node[3][1][1].split('');
for (j = 0; j < characters.length; j++) {
var character = characters[j].toLowerCase();
if (this.characterMap[character] == null) {
this.characterMap[character] = new Object();
this.characterMap[character][node[3][0][1]] = true;
}
else {
var index = this.linearSearch(node[3][0][1], this.characterMap[character]);
if (index == -1) this.characterMap[character][node[3][0][1]] = true;
}
}
}
}

7/21/2010 10:52:36 AM

FroshKiller
All American
51908 Posts
user info
edit post

What are you trying to do?

7/21/2010 10:53:06 AM

OmarBadu
zidik
25067 Posts
user info
edit post

it's a dropdown control that has a tree inside of it - this is enabling searching the tree - it loads each character into a hash map

the problem occurs once there are a large number of nodes in the tree - IE throws an unresponsive warning after 5 million statements are executed (regardless of time) and this is the issue - it performs well but there are too many statements being executed for IE

7/21/2010 11:06:03 AM

FroshKiller
All American
51908 Posts
user info
edit post

How many items typically appear in your list? What is your expected maximum?

7/21/2010 11:09:07 AM

Shaggy
All American
17820 Posts
user info
edit post

maybe im an idiot or something but idk how this would even work? you set count to 0, then the first thing you do in the top for loop is increment count. Then you check to see if count is 0 (which it wont ever be because you incremented it).

[Edited on July 21, 2010 at 11:12 AM. Reason : k]

7/21/2010 11:12:13 AM

Shaggy
All American
17820 Posts
user info
edit post

oh, hurrrr

faggot style braces. nevermind.

7/21/2010 11:12:44 AM

FroshKiller
All American
51908 Posts
user info
edit post

hahaha

[Edited on July 21, 2010 at 11:13 AM. Reason : n/m]

7/21/2010 11:12:52 AM

Shaggy
All American
17820 Posts
user info
edit post

allman style or get out

7/21/2010 11:15:04 AM

FroshKiller
All American
51908 Posts
user info
edit post

Also, is the options set static? If it is, why make the client build the hash every time the page is loaded? You could build the hash once and just pass 'em the object, ready to use.

7/21/2010 11:17:27 AM

OmarBadu
zidik
25067 Posts
user info
edit post

i didn't write this - i'm just angry that it's shit

i've already removed that ridiculous for loop at the beginning and just set count=1 as the last statement in the outside if statement - i'm not sure who thought that was acceptable

^ great point - the data is not necessarily static but arguably it doesn't change "often" and when it did the hash map could be rebuilt then

the issue is that i'd have to get another build of the entire project as opposed to updating this single javascript file that can be done "behind the scenes"

7/21/2010 11:17:51 AM

Shaggy
All American
17820 Posts
user info
edit post

that nodemap[3][0][1] looks goofy as shit. idk wth it is or really anything about how people normally do javascript stuff, but i tell you waht i dont like it one bit. no sir

7/21/2010 11:20:24 AM

FroshKiller
All American
51908 Posts
user info
edit post

Without seeing some examples of this actually in use, I can say that you should probably do everything you can to minimize the size of the option list provided to the client. Maybe there's some way you could qualify what items are needed in the list based on other form inputs.

I'm very much in favor of refining the process and interface first and the algorithm second. 'Cause really, hashing every character is only gonna give you an advantage in speed if the data set is HUGE, and if the data set for one measly list is that big, someone probably fucked up (or you'd be better off processing it server-side and passing the hash to the client when it's done [in which case you should probably just use an autocompleting text input field]).

[Edited on July 21, 2010 at 11:23 AM. Reason : ...]

7/21/2010 11:20:49 AM

Stein
All American
19842 Posts
user info
edit post

Can you post an example of what your data source looks like currently? I'm having trouble completely wrapping my head around what this is trying to do.

7/21/2010 11:42:48 AM

 Message Boards » Tech Talk » Inefficient Javascript Causing Error in IE Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.