What I find in the literature is that argument type management matters a lot for the compiler to improve Performance:
A1.- Type-stability
In order for the Julia compiler to compile a specialized version of a function for each different type of argument, it needs to infer, as best as possible, the parameter and return types of all functions. If it doesn’t do this, the speed of Julia will be hugely compromised. In order to do this effectively,
the code must be written in a way that it is type-stable.
Sengupta, Avik. Julia High Performance: Optimizations, distributed computing, multithreading, and GPU programming with Julia 1.0 and beyond, 2nd Edition (English Edition) (p. 41). Packt Publishing. Edición de Kindle.
A2.- “You will work with a function for calculating the roots of a quadratic equation:”
ax² + bx + c =0
…The reason for the slow performance of the quadratic1 function is that it is not type-stable. In Julia,
*** this means that the compiler is generally unable to determine the types of all variables used in the body of the function.***
There are two possible reasons for this. One is that the type of the variable changes during execution of the function, and the other is that there is some obstacle preventing type inference from working (at least at the current stage of the Julia compiler).
In this recipe, we discuss the second problem, as it is subtler. The first one (changing of the variable type) is much simpler and is explained in detail in the Julia manual at…
Bogumił Kamiński, Przemysław Szufel. Julia 1.0 Programming Cookbook
Copyright © 2018 Packt Publishing.Over 100 numerical and distributed computing recipes for your daily data science workflow
B.- Chapter::Types, Type Inference, and Stability.
Julia is a dynamically typed language. Unlike languages such as Java or C, the programmer does not need to specify the fixed type of every variable in the program. Yet, somewhat counterintuitively, Julia achieves its impressive performance characteristics by inferring and using the type information for all the data in the program. In this chapter, we will start with a brief look at the type system in the language and then explain how to use this type system to write high-performance code.
…
Sengupta, Avik. Julia High Performance: Optimizations, distributed computing, multithreading, and GPU programming with Julia 1.0 and beyond, 2nd Edition (English Edition) (p. 33). Packt Publishing. Edición de Kindle.
C.- Fixing type instability.
Now that we can recognize type-unstable code, the question arises: how can we fix code such as this?. There are two obvious solutions.
One would be to write separate versions of the pos function for different input types. So, we could have a version of pos for integers and another for floating points. However, this would cause instances of repeated, copy-pasted code. Also, there would not just be two such instances; there would be copies for Float32, Float64, Int32, Int64, and so on. Further, we would have to write a new version of this function for all the new numeric types that were defined. It should be obvious that writing generic functions that operate on a wide variety of related types is really the best way to get concise and elegant Julia code.
The second obvious solution is to branch out the input type within the generic function. So, we could write code along these lines, as follows:…
Sengupta, Avik. Julia High Performance: optimizations, distributed computing, multithreading, and GPU programming with Julia 1.0 and beyond, 2nd Edition (English Edition) (p. 42). Packt Publishing. Edición de Kindle.
…