# Some notes on performance of callable structs

**URL:** <https://discourse.julialang.org/t/some-notes-on-performance-of-callable-structs/108042>\
**Category:** Performance\
**Created:** [December 25, 2023, 5:32pm UTC](https://discourse.julialang.org/t/some-notes-on-performance-of-callable-structs/108042 "2023-12-25T17:32:14Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [December 25, 2023, 6:36pm UTC](https://discourse.julialang.org/t/some-notes-on-performance-of-callable-structs/108042/3 "2023-12-25T18:36:36Z")

</div>

This is almost a repeat of this recent thread:

> [@Tricks to compile away step in calculation?](https://discourse.julialang.org/t/tricks-to-compile-away-step-in-calculation/105760):
>
> Is there a way to compile away a step in a calculation internal to some function called in a closure but without manually decomposing the function into its constituent calculations within the closure? Below I provide a MWE in OLS because this is the simplest example I could think of: suppose we are going to run a loop of regressions using the same covariates but different outcome variables. We use a closure to create a new function that treats covariates as a constant. my\_pinv(X) = (X'X)^-1 \*…

My answers there are somewhat relevant here, too.

I’d like to emphasize, though, that your perspective here seems wrong. There’s no “problem” here, nothing “bad”, and nothing to “fix”, although hypothetically there could be opportunities to improve some things, of course. Julia is the leader in compile-time computation among programming languages, given that it allows moving values into the type domain, making Julia more powerful than even the great C++ (whose template meta-programming, and other compilation time computation features apply strictly _before_ run time).

Also, like in the linked thread, I think you may not realize that the limitations involved here are quite essential. We, as Julia programmers, **want** the Julia compiler to only get involved when we expect it to, which conflicts with your implicit expectation that the compiler would move values into the type domain of its own accord, without being prompted to do something by the programmer.

---

_[View the full topic](https://discourse.julialang.org/t/some-notes-on-performance-of-callable-structs/108042)._
