First of all, there is no need to translate literals. x = 1.0 same as x = scalar(1.0) if x already has a type scalar.
There is no such thing as a custom type alias in Go. In Go, bytes and uint8 (which are built-in types) are considered aliases of each other. These are two names for the same type. Float64 and scalar are not the same. The values of float64 and scalar must be converted between themselves using something like s = scalar(f) , while bytes and uint8 do not.
However, such conversions have no overhead. Types are used at compile time to ensure that the code is correct, but do not affect runtime performance. Execution is only affected if you make type statements or use reflection. However, these differences affect logic, not performance.
Can I use this when performance is absolutely critical?
Yes
source share