[jQuery] Re: how to avoid overhead
Thank you!! I will try your code soon. But the solution makes sense. I can't test in IE, cause I'm a linux user and need install VMware or something like this. I will feedback to you. Dirceu Barquette 2008/12/2 Michael Geary <[EMAIL PROTECTED]> > > You're right to question the requirement to add that many divs. But > assuming > it's necessary, that code is not the fastest way to do it. This would be > faster, especially in IE: > >var n = 1600; >var html = new Array( n + 2 ); >html[0] = ''; >for( var i = 1; i <= n; ++i ) >html[i] = ''; >html[i] = ''; >$( html.join('') ).appendTo('#parentDiv'); > > There are several reasons this is faster: > > 1) It stores the HTML text in an array, then joins the array when it's > completed. This is much faster than string concatenation in IE. Also: > >1a) It preallocates the array at its final length. > >1b) It stores the values directly in the array elements instead of using > array.push(). > > 2) It wraps all of the divs in one container div, i.e. the resulting HTML > (with whitespace added for clarity) is: > > > >... > > > > Actually I'm not sure if #2 makes a difference in this case - I'd have to > test it. But #1 can make a big difference. > > -Mike > > > From: [EMAIL PROTECTED] > > > > I would start by evaluating the requirement for adding 1599 divs. > > The way you have written it is probably the most efficent > > cross browser way of appending that much content but it will > > still crawl. > > > > On Dec 2, 10:53 am, "Dirceu Barquette" <[EMAIL PROTECTED]> > > wrote: > > > Hi! > > > > > > The code: > > > for (i = 0; i < 1600 ;i ++) { > > > htm += '';} > > > > > > $(htm).appendTo('#parentDiv'); > > > > > > How can avoid overhead? > > > > > > thanks, > > > > > > Dirceu Barquette > > > >
[jQuery] Re: how to avoid overhead
You're not going to get good enough performance from handling thousands of elements. I tried that myself last year: http://ff6600.org/desenhador/ff66.htm It used to run ok in FF2, but somethign in FF3 makes it really slow. If you draw with the middle-mouse button performance is better (I didn't cancel the context menu), guess it's still selecting stuff when you use left click. A better approach is using the canvas element, or maybe SVG/VML. A lot has been done in this area: http://canvaspaint.org/ http://raphaeljs.com/ 'Raphael and Isabela' sounds like a nice couple :D - ricardo On Dec 2, 11:02 am, "Dirceu Barquette" <[EMAIL PROTECTED]> wrote: > Thank you!! > please! see the example at isabeladraw.sourceforge.net. I've been forced > build blocks against the entire board. But I'm thinking create > child-by-child onmouseover position. > sorry my english... > > Dirceu Barquette > > 2008/12/2 [EMAIL PROTECTED] <[EMAIL PROTECTED]> > > > > > I would start by evaluating the requirement for adding 1599 divs. > > The way you have written it is probably the most efficent cross > > browser way of appending that much content but it will still crawl. > > > On Dec 2, 10:53 am, "Dirceu Barquette" <[EMAIL PROTECTED]> > > wrote: > > > Hi! > > > > The code: > > > for (i = 0; i < 1600 ;i ++) { > > > htm += '';} > > > > $(htm).appendTo('#parentDiv'); > > > > How can avoid overhead? > > > > thanks, > > > > Dirceu Barquette
[jQuery] Re: how to avoid overhead
You're right to question the requirement to add that many divs. But assuming it's necessary, that code is not the fastest way to do it. This would be faster, especially in IE: var n = 1600; var html = new Array( n + 2 ); html[0] = ''; for( var i = 1; i <= n; ++i ) html[i] = ''; html[i] = ''; $( html.join('') ).appendTo('#parentDiv'); There are several reasons this is faster: 1) It stores the HTML text in an array, then joins the array when it's completed. This is much faster than string concatenation in IE. Also: 1a) It preallocates the array at its final length. 1b) It stores the values directly in the array elements instead of using array.push(). 2) It wraps all of the divs in one container div, i.e. the resulting HTML (with whitespace added for clarity) is: ... Actually I'm not sure if #2 makes a difference in this case - I'd have to test it. But #1 can make a big difference. -Mike > From: [EMAIL PROTECTED] > > I would start by evaluating the requirement for adding 1599 divs. > The way you have written it is probably the most efficent > cross browser way of appending that much content but it will > still crawl. > > On Dec 2, 10:53 am, "Dirceu Barquette" <[EMAIL PROTECTED]> > wrote: > > Hi! > > > > The code: > > for (i = 0; i < 1600 ;i ++) { > > htm += '';} > > > > $(htm).appendTo('#parentDiv'); > > > > How can avoid overhead? > > > > thanks, > > > > Dirceu Barquette >
[jQuery] Re: how to avoid overhead
Thank you!! please! see the example at isabeladraw.sourceforge.net. I've been forced build blocks against the entire board. But I'm thinking create child-by-child onmouseover position. sorry my english... Dirceu Barquette 2008/12/2 [EMAIL PROTECTED] <[EMAIL PROTECTED]> > > I would start by evaluating the requirement for adding 1599 divs. > The way you have written it is probably the most efficent cross > browser way of appending that much content but it will still crawl. > > On Dec 2, 10:53 am, "Dirceu Barquette" <[EMAIL PROTECTED]> > wrote: > > Hi! > > > > The code: > > for (i = 0; i < 1600 ;i ++) { > > htm += '';} > > > > $(htm).appendTo('#parentDiv'); > > > > How can avoid overhead? > > > > thanks, > > > > Dirceu Barquette >
[jQuery] Re: how to avoid overhead
I would start by evaluating the requirement for adding 1599 divs. The way you have written it is probably the most efficent cross browser way of appending that much content but it will still crawl. On Dec 2, 10:53 am, "Dirceu Barquette" <[EMAIL PROTECTED]> wrote: > Hi! > > The code: > for (i = 0; i < 1600 ;i ++) { > htm += '';} > > $(htm).appendTo('#parentDiv'); > > How can avoid overhead? > > thanks, > > Dirceu Barquette