OZONE Asylum
Forums
DHTML/Javascript
IE JS/DOM performance degradation weirdness
This page's ID:
27610
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Firstly, hello! (As I'm sure with many of yourselves, I've been busy - lots of ajax-enabled/web 2.0 apps to build out there.) ;) OK, all jokes aside - a serious question for the local JS gurus. I have run into some issues with IE (and only IE,) where it appears to be that the browser's DOM handling from within Javascript is degrading in a linear fashion as I'm adding nodes and creating JS objects. In most cases, this may be expected behaviour - but I am taking steps to keep the load light in terms of rendering performance and DOM load (eg. number of elements) - plus this is an IE-only issue (Firefox does not exhibit this behaviour,) so I suspect something particular to IE's JS/rendering engine. I'm building a fairly heavy page that uses "pages" of content (Javascript-driven so you stay on the same page,) where new elements and JS objects are being created to track the properties and events relating to these elements. For conceptual reference, it's like a tabular spreadsheet-type sort of application. Each "page" of data is created and rendered on-the-fly (eg. I'm creating a bunch of elements as efficiently as possible, creating JS objects for these, attaching objects->elements and finally appending to the document.) I have noticed that this process (preparing data -> creating elements -> creating objects -> linking objects+elements -> append to body) takes ~500 ms more for *each* successive new page in IE (CPU use is 100% during this time,) despite that I'm actively hiding/removing previously-created (non-displayed) pages as I go. Regarding efficiency in moving between existing pages: when you view page 2 for example, page 1 is removed from the DOM (but stored in a JS object for when you go back to that page, at which point it is re-inserted.) Obviously I also need to maintain state of changes that may have been made, so it's simplest to let the Javascript objects remain in memory rather than destroy them and try to dynamically re-create, etc. I was previously doing a simple "show/hide" of page content after it had been written to the document, but figured this was perhaps the cause of the growing slowness in IE (more elements = slower.) Unfortunately, even now (swapping out these nodes) does not seem to make a difference. I tried a few other tricks like setting document.body.style.display to 'none', to see if it was perhaps related to rendering - that didn't seem to help. It appears that several DOM methods like getElementsByTagName() are slowed down here (and are used extensively in creating a new page,) but others such as cloneNode() seems to be relatively unaffected. I suspect the DOM may be "flooded" by a large number of elements and therefore slow (having to parse a very large tree,) even though I am actively removing "hidden" pages so that only one is actually appended to the document body and visible at any given time and also scoping the getElementsByTagName() call to the smallest "branch" to minimize the number of nodes involved. The degradation seems to be quite linear as well, as I am almost always creating the same number of new elements and objects. It appears to be tied directly to the total amount of "stuff" present within the document or JS environment - unfortunately, I have not yet determined if one or the other are specifically responsible. Navigating away from / unloading the page / reloading solves this issue, it is not like a memory leak which "persists" across pages etc.. it is more typical: just within one page view, and only after a large number of elements + JS objects have been created. Has anyone else seen this kind of issue, or am I just crazy? ;) (Then again, this is the Asylum after all.) Thanks! [small](Edited by [url=http://www.ozoneasylum.com/user/2276]Scott[/url] on 03-08-2006 04:07)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »