Performance Tips
Performance Tips
In the following sections, we briefly go through a few techniques that can help make your Julia code run as fast as possible.
Avoid global variables
A global variable might have its value, and therefore its type, change at any point. This makes it difficult for the compiler to optimize code using global variables. Variables should be local, or passed as arguments to functions, whenever possible.
Any code that is performance critical or being benchmarked should be inside a function.
We find that global names are frequently constants, and declaring them as such greatly improves performance:
const DEFAULT_VAL = 0
Uses of non-constant globals can be optimized by annotating their types at the point of use:
global x y = f(x::Int + 1)
Writing functions is better style. It leads to more reusable code and clarifies what steps are being done, an