views:

412

answers:

3

I have some performance issues in my JavaScript, and I'm not having much success instrumenting it. One of the things I've tried is using firebug's profile tool. It reports that the top single call was to dojo's log(). Unhelpfully, it reports a line number from the compressed script, so I can't tell what's causing the problem. But it seem interesting that 70% of the lines in the profile report are for dojo's log() calls, so cumulatively, it must be spending an amazing amount of time there. Is there a way to turn off dojo logging?

The only visible logging is an entry that shows up every 1.5 seconds and that appears to be a keep alive for comet. I'm also using dojo's slider in one place, but I don't see any evidence that that's causing a performance hit.

What other tools should I use to try to identify performance hot spots in javascript? The portion of my code that is in JavaScript is not really very large, so it wouldn't surprise me if it was round trips to the server that are really causing the problem, but I don't know how to instrument that either.

A: 

If you are using Dojo 1.2 or higher you can use stripConsole=normal while making your build to automatically strip all log calls it makes. If you are not using the build system then that's probably the #1 thing you can do to improve performance.

Some links to get you started:

http://docs.dojocampus.org/build/index

http://docs.dojocampus.org/quickstart/custom-builds

Marijn
I've browsed around dojotoolkit.org, and I don't see anything about building. Everything seems to assume you'll want to use a ready-made version. Can you give a pointer to the build directions and what to download?
PanCrit
I added the links. If you've never seen those docs: They're a little slow and not structured in the best probably way, but there's a lot of really good information in there.
Marijn
A: 

Try building your JavaScript too, using the Dojo builder. Also, remember that the slowest calls are DOM calls. So make sure you're not querying the DOM inside a loop when it could be moved outside.

Wahnfrieden
Very slow? Compared to what? Last time I had this problem was in Dojo 0.4. The current version is 1.3.
Eugene Lazutkin
It's very slow, compared to not using it. Of course generating nodes and objects directly via JavaScript will be faster than making Dojo parse the DOM first before creating anything.
Wahnfrieden
Either you have a huge DOM, or you measure the wrong thing. Did you try to surprise people in the Dojo mailing list with that?
Eugene Lazutkin
If you're saying the parser is slow, you're saying that Dojo's CSS selector code is slow. If you're saying Dojo's CSS selector code is slow, you're saying that all CSS selector code is slow, as we've always been at the top of the pack. Look at any of the CSS profiling tests, look at the slowest test, see if that number is really high enough to matter.
pottedmeat
Sorry, I overstated it and haven't thoroughly tested the latest versions with respect to the parser. I just recalled reading that advice (avoid the parser to improve performance) from one of the Dojo contributors, but it must have been something old. Thanks for the correction.
Wahnfrieden
+1  A: 

You are likely using a compressed version of Dojo. If you change dojo.js to dojo.js.uncompressed.js, the profile information should show you much more accurate information.

pottedmeat
I thought I had tried that and not gotten any more information. I'll try again.
PanCrit