Hello,
I am trying to understand how passing function outputs between modules work and I would like to know if my reasoning is correct.
Let’s assume we have the following modules:
module M1
function foo()
a = [1,2,3]
end
end
module M2
import ..M1
function bar(x)
b = x.+1
end
# 1.
aux = M1.foo()
c = bar(aux)
# 2.
c = bar(M1.foo())
end
Does this mean that “aux” (which is global variable in M2) will impact performance of function “bar” in approach # 1.?
What if we use approach # 2. ?
Thank you!
No. The use of global variable will affect the code that uses it. So the performance of bar(aux)
will be affected but the performance of the code in bar
shouldn’t.
3 Likes
I believe there will be a small performance impact when using aux
since it’s global and Julia needs to verify the type before passing it to bar. But that should be it. When passing the value directly without using a global variable Julia is able to verify the type returned from foo and pass it to bar when the code is compiled.
Now it’s clear. Thank you all for your help!