Usage of @code_warntype in Julia

Depending on your version of julia, @code_warntype can sometimes flag certain expressions that are harmless. With a little bit of practice you can easily recognize these expressions (e.g., they often have to do with module/name lookup).

The easy path, as Reza says, is to look at the variables section and the function's return-type; if you don't see any type-uncertain quantities (either Any or Unions) you probably have nothing to worry about. If you want to dig deeper, start trying to make sense of the body expressions that it's flagging. For learning, one useful thing to do is compare the results against those obtained with track-allocation, since true type instability is associated with memory allocation.

However, I think the issues with @code_warntype have been fixed on current master, so in any case the next release of julia should make it easier to interpret.


Normally it's not necessary to search body part for more so-called non-leaf types, because the code_warntype main task is to do this job for you, (check source). But the body part have more informations about where and how this non-leafs have been used.

References:

  1. code_warntype(f, types) in documentation.
  2. code_warntype(f, types) source.

Tags:

Types

Julia