@code_warntype shows lots of Union{Nothing, Tuple{Int64, Int64}}

I’m working through @ChrisRackauckas excellent article 7 Julia Gotchas and How to Handle Them - Stochastic Lifestyle. One of his big recommendations is to use @code_warntype.

I already found an untyped container that made things a lot faster when I fixed it.

However, now I see lots of Union{Nothing, Tuple{Int64, Int64}}. I’m looking through my code (the vrr routine, not that I’m asking anyone to debug code for me), and I just can’t find anything that would lead to variables of that type. The only other hint I have is that all of these variables have an @_53 or some other number in front of them, which I’m guessing means that they’re intermediate variables, i.e.:

  i@_52::Int64
  @_53::Union{Nothing, Tuple{Int64, Int64}}
  @_54::Union{Nothing, Tuple{Int64, Int64}}
  @_55::Union{Nothing, Tuple{Int64, Int64}}
  @_56::Union{Nothing, Tuple{Int64, Int64}}
  c_i::Float64

Does this ring any bells for people, or can people suggest useful directions to pursue?

Thanks in advance.

The main place you see Union{Nothing, something_else} is from for loops. These lower to iterate(iter,state) which either returns the next state or nothing.

You don’t need to worry about this. Julia is able to generate efficient code for small unions (unions of 4 or less types).

5 Likes

Excellent.That makes a lot of sense. Thanks for your help!

Yeah, Julia’s compiler fixed this and a lot of the other gotchas.

I should write a follow up post, “7 Julia Gotchas and How They Were Handled”

5 Likes

@ChrisRackauckas Would love to see a follow-up article. That, plus the Julia Performance Tips, have been the best resources I’ve found to speeding my code.

These days I’d recommend my lecture notes on serial code performance:

https://mitmath.github.io/18337/lecture2/optimizing

From GitHub - mitmath/18337: 18.337 - Parallel Computing and Scientific Machine Learning

5 Likes

Excellent. Thanks!

Are the other 6

  1. Issue 265
  2. higher order function performance
  3. putting views on the stack
  4. what are abstract types?
  5. what are arrays?
  6. how do we clone people named Chris?
3 Likes