# Performance when passing function outputs between modules

**URL:** <https://discourse.julialang.org/t/performance-when-passing-function-outputs-between-modules/26121>\
**Category:** New to Julia\
**Created:** [July 7, 2019, 7:27pm UTC](https://discourse.julialang.org/t/performance-when-passing-function-outputs-between-modules/26121 "2019-07-07T19:27:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [July 7, 2019, 7:27pm UTC](https://discourse.julialang.org/t/performance-when-passing-function-outputs-between-modules/26121/1 "2019-07-07T19:27:51Z")

</div>

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:

```julia
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!

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [July 7, 2019, 8:11pm UTC](https://discourse.julialang.org/t/performance-when-passing-function-outputs-between-modules/26121/2 "2019-07-07T20:11:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [July 8, 2019, 11:39am UTC](https://discourse.julialang.org/t/performance-when-passing-function-outputs-between-modules/26121/3 "2019-07-08T11:39:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [July 9, 2019, 3:59pm UTC](https://discourse.julialang.org/t/performance-when-passing-function-outputs-between-modules/26121/4 "2019-07-09T15:59:57Z")

</div>

Now it’s clear. Thank you all for your help!
