[ANN] New tools for fixing performance problems in Julia

Many questions on discourse center around performance, and one common category of problems is “type instability” (aka, poor inferrability triggering runtime dispatch). While the @code_typed and similar macros are powerful, they can be somewhat daunting for newcomers and, for some functions, rather verbose and thus a lot to wade through even for experienced Julia developers.

We just released Cthulhu 2.8, which we hope may simplify this kind of analysis. Some of you may know Cthulhu as an amazingly powerful tool, but since it’s basically “@code_typed on steroids,” it poses most of the same challenges. In Cthulhu 2.8, the default setting attempts to map inference results back to your source code. Here’s a quick screen shot showing this in action:

The white text is directly from the source code; the colorful type-annotations are added by Cthulhu. There are different viewing modes available; for example, depending on how you launch it the cyan-colored annotations (which are attached to well-inferred objects) may be hidden (but you can hit 'h' to toggle their visibility).

Moreover, ProfileView now exports a couple of additional tools that interact with Cthulhu, so that you can profile a job and then click on red bars and be taken directly to the source of the trouble. You can also “ascend” back up the chain of calls to make it easier to find out whether it’s one of the callers that’s to blame for the problems.

Because it’s an interactive tool, I’ve also prepared a video if you want to see it in actual use.

Finally, I do want to caution you that, especially in these early days, these new capabilities are likely to be a bit buggy or fragile. Mapping the results of type-inference back to the source code is nontrivial, and the results are sure to contain errors or omissions. When in doubt, you should check the traditional type-view (hit 'T') if you know how to read it. Please do file issues (or better, make pull requests!), as that will help it incrementally improve. But as a reality-check, I’m guessing that until Julia’s lowering & type inference stages get rewritten to keep track of their origins in the source-text, perfection is probably unobtainable. Time will tell whether the new simpler views will give benefits that exceed any problems they cause.

Good luck in stomping out the red!


This is amazing! It finally convinced me to add Cthulhu to my base environment :partying_face: Excited to try it out


Hi, Tim! Thank you for this new feature; it is looking great!

Question: what is the opposite of runtime dispatch? JIT dispatch?

Static dispatch, as opposed to dynamic. This could also be called “no dispatch” because it compiles based on a single known method.

1 Like