Does Julia optimise when we reuse function?

I have the following two functions defined separately.

C(u_nodes, X, t) = F(u_nodes, X, t)'F(u_nodes, X, t)
b(u_nodes, X, t) = F(u_nodes, X, t)* F(u_nodes, X, t)'

Now, if I create another 2 functions (called in a sequential order) which uses the above functions S=f(C), σ=f(b), does the F function get calculated again or does it get optimized by julia that it is calculated only once? Or, in other words, is calculating the actual matrix necessary or can I just keep on calling function of functions all the way down?

Julia is allowed to make this optimization if it can prove that F is pure (doesn’t mutate state, including IO). That said, this is hard optimization to do since it requires C and b to be inlined before the compiler is able to see that this optimization is possible, and proving purity can be difficult.

1 Like

Thanks for the reply. What is meant by “inlined”?

1 Like

Thank you!