Skip to main content

Optimisation for Julias

Julia optimisation is the discipline of making code fast by helping the compiler: type stability, avoiding global variables, preallocating arrays, reducing allocations and measuring with profilers. It belongs to the Performance stage and explains why the same algorithm can differ by a factor of one hundred depending on how it is written.

Stage: Performance · Part of the Julia roadmap · Last reviewed 19 November 2026

What to learn in Optimisation

Optimisation interview questions

What is type stability in Julia?

A function is type stable when the type of its return value can be inferred from the types of its inputs. Stable code lets the compiler generate specialised, fast machine code. Unstable code forces runtime checks and allocation, and shows up as Any or Union in @code_warntype.

Why are global variables slow in Julia?

A non-constant global can change type at any time, so the compiler cannot assume anything about it inside a function. Passing the value as an argument or declaring the global const lets the compiler specialise code and removes the overhead.

Where Optimisation fits in the Julia roadmap

Optimisation belongs to the Performance stage (intermediate level). Make it fast.

Back to the full Julia roadmap