The Julia Language Docs have a great page on performance tips.  It's worth a read, but the writing is aimed more towards a computer scientist than a

Performance Tips

submited by
Style Pass
2021-06-08 22:00:02

The Julia Language Docs have a great page on performance tips.  It's worth a read, but the writing is aimed more towards a computer scientist than a data scientist. Here we'll cover some easy performance wins.

Speeding up bottlenecks is usually straightforward in Julia, often involving drop-in replacements (like using StaticArrays for small, fixed arrays).  There are, however, some performance gotchas you should avoid from the start so that you don't need to refactor code later on.

Type stability is the idea that the return type of a function only depends on the types of the inputs, not the input values.  Here is an example of  a type-unstable function:

The issue with the function above is that Julia's compiler needs to handle multiple cases (output could be either a String or an Int).

Try not to initialize a variable with a type that will change later because of some computation.  For example, starting with x = 1 but then performing division x = x/2 will change x from Int to Float64.

Leave a Comment