Out of professional curiosity: What is the maximum depth for inlining function calls in Julia in practice?
My programming intuition says that there must exist a practical limit regarding how deeply nested functions may be before they are not inlined anymore. Is this a fixed (possibly configurable) number? Or does it depend on some compiler heuristics? And if yes, what are the limits in practice that people have experienced?
I am asking since Julia favors manysmall functions and we’ve tried to do this in Trixi.jl. However, people coming from other languages (ahem C++ or Fortran ahem) still cringe when they see it, and I’d like to back my claim that small functions make for fast code with some hard numbers during the next discussion
As mentioned on Slack, I generated 52 functions each which calls the previous, where the final step calls sum (which itself has a call stack 13 functions deep), and that all inlined.
So if there is a limit, it’s at least 66 layers deep - and will probably never be reached in practice.
I deleted the code, but it was something along the lines of
@inline a(x) = sum(x)
for i in 'b':'z'
@eval @inline $(Symbol(i))(foo) = $(Symbol(i - 1))(foo)
end
I also added another loop with the capital letters. It’s easy to extend this as far as you want. To determine whether it inlined, I did @code_native z([1])