I'm in the process of writing a jQuery plugin, and am getting into some fairly heavy operations, which is making my plugin slower and less responsive. I was wondering if there was any tools out there that would help me optimize my JavaScript?
Its difficult to say without looking at at any code, ie how efficiently things have been written eg: how you're using selectors to find elements etc.
Have a look at some jQuery tips and tricks blogs.
eg:
http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx
I recommend using Firebug's "profile" tab as a start.
Just click the profile tab, then use your plugin for a while and then click the profile tab again. You'll then see a report of what functions were called and how much time each one took.
Then, I recommend the article Speed up your JavaScript
As outlined in the article, why a script can take too long to execute
- Too much happening in a loop.
- Too much happening in a function.
- Too much recursion.
- Too much DOM interaction.
I have not yet found a tool that automatically optimizes or refactors JavaScript for speed. It's always been a manual process for me.