June 2019
Intermediate to advanced
218 pages
5h 19m
English
Type stability has been historically very important for high-performance Julia code. In Julia 1.0, however, the compiler has improved significantly to the extent that simple instances of type instability can easily be optimized out, ensuring that simple type-unstable code is almost as fast as type-stable code. This is achieved via a compiler technique called union splitting.
Measuring the function runtimes in the following listing, we can see that the type-unstable version is only slightly slower than the type-stable one:
julia> @btime pos(2.5) 0.032 ns (0 allocations: 0 bytes)2.5julia> @btime pos_fixed(2.5) 0.031 ns (0 allocations: 0 bytes)2.5
In older versions of Julia, this would have been half as fast as
Read now
Unlock full access