Open willowless opened 10 years ago
There is a problem with inlining of methods on Vector2
, I've come across this myself. I hope to just solve that once and for all soon, by making tuples acts as n vectors so the ImmutableArrays hack shouldn't be necessary. I also have some thoughts on how to improve type inference and I will make sure that this package works as expected with no overhead in the usual cases (part of what I'll be focusing on this summer). Thank you for the issue report though. I'll be sure to test this after.
The SIUnits is great because it ends up doing a no-op when the type of the quantity is the same. However, when you're using a composite type to represent a vector, such as with ImmutableArrays (or other code similar to it), for some reason the SIQuantity.+ method does not inline, despite all type information being resolved:
In this method you can see the SIQuantity.+ in Julia 0.2.0. Tim Holy also had a go with a newer version of Julia and replied the following to me: "With regards to your specific question, my version of Julia (a relatively recent build from master) inlines the "+" operation but still issues a pair of calls for a conversion; I agree those seem unnecessary."
The JIT is not inlining the calls either, so the native code on my x86_64 platform ends up like this: code_native(+, (Vector2{typeof(0m)}, Vector2{typeof(0m)}))
It's possible MCJIT will magically inline at the native code level, but I would have thought Julia would have inlined at the LLVM IR level. My assumptions about how, why and when it would inline are probably invalid though.
I hope this helps.