in

Emerald Hand

Emerald Hand, Inc. community home page.

This Blog

  • Home
  • Contact
  • About
  • Directory of Computers/Tech Blogs

Syndication

News

I'm back to blogging

Worm in liquid maze

Design and development of information management tools.

Improving JavaScript performance

I didn’t get to promoting my blog yet. Not enough free time. Nevertheless, that is what I’m planning to do next right after I finish this post.

I spent a lot of time lately working on improving JavaScript performance using Mozilla’s debugger. It’s free and collects all the data I need, as well as outputs it in .csv format for any spreadsheet application to read. The only downside is that it only works on Mozilla or Firefox. Scripts that I optimize do start to run faster in IE as well, but I don’t get to see what actions take longer to complete in IE vs. Firefox. I do get a feeling that scripts run faster in Firefox, but that script engine initializes faster in IE. In other words, the code loads and starts executing earlier in IE, but takes less time to run in Firefox. I haven’t confirmed this and I don’t see a good and easy way of doing it.

There are couple of things that I’ve learned about JavaScript performance. It’s slow, much slower than compiled or hybrid (like .NET) languages and so it is much more important to balance objects reuse vs. creating new ones. Object creation can become very expensive if there are 100s of them created. On the other hand, caching and object reuse can make code more complex. Balancing one vs. the other becomes more important in JavaScript since the margin of error in design is smaller.

Another thing I’ve noticed is that function declaration in local scope can become expensive if the code inside local scope is executed 100s of times. For example if you’re expecting that some object will be created often try to take as many functions declarations out of the constructor and into the prototype as possible. This is in essence the problem of object reuse vs. new object initialization, since functions are objects too. I did not expect this to be a problem and ended up having to refactor the code around. The code performance increased by around 40% according to the profiler. That’s quite a lot! In the future, I hope to avoid these problems.

Share this post: Email it! | bookmark it! | digg it! | reddit!
Readability Stats: Word Count: 371; Sentence Count: 28; Grade Level: 6.8, more info...
Published May 30 2005, 12:24 PM by Ornus
Filed under:

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add

About Ornus

Lead Sider and Xelog developer. I'm interested in information and how we can better manage it using computers. I'm also into design and understanding how to creating cool, useful, simple things.
Copyright © 2006-2007 EmeraldHand, Inc. All rights reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems