Page 1 of 1

JavaScript Optimizations

Posted: Tue Apr 11, 2006 10:30 am
by Chris Corbyn
Hiya!

Often lately when I write JS that does something DHTML-ish (i.e. something that animates) I find it runs very slowly on what I would call an average PC (1.5GHz CPU, 512MB RAM). Even slower if testing it in IE.

Does anyone know any good links/resources that deal specifically with optimizing JavaScript code that does fancy things like animations?

I also occassionally find IE hanging before deciding to process JS even on fairly basic DHTML pages (using DOM.... does IE recurse the whole DOM tree before executing functions etc or something?).

Cheers,

d11

Posted: Tue Apr 11, 2006 2:01 pm
by feyd
I've found that it can often have to do with memory allocations being issued and removed. The garbage collection routines seem to be rather poorly implemented in many browsers.

Posted: Tue Apr 11, 2006 6:14 pm
by Chris Corbyn
feyd wrote:I've found that it can often have to do with memory allocations being issued and removed. The garbage collection routines seem to be rather poorly implemented in many browsers.
This is my thinking too. A particular page declares an array. That array then has anywhere between zero and 365 items added to it on page load (once-only) (can you guess what it's for? :P).

Now that in itself should not be an issue in most languages. For some reason however, once that array has been filled something as simple as a rollover will have a noticable delay in Internet Explorer.... rather odd :( It's not specific to just that script neither, I tend to find this a lot when working with arrays in JS.

Posted: Wed Apr 12, 2006 5:47 am
by Weirdan
Not particularly optimization, but good to know nevertheless: http://del.icio.us/bweirdan/javascript+bug