# Can macros also be precompiled?

**URL:** <https://discourse.julialang.org/t/can-macros-also-be-precompiled/83032>\
**Category:** Performance\
**Tags:** question, macros\
**Created:** [June 19, 2022, 10:20pm UTC](https://discourse.julialang.org/t/can-macros-also-be-precompiled/83032 "2022-06-19T22:20:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [June 19, 2022, 10:20pm UTC](https://discourse.julialang.org/t/can-macros-also-be-precompiled/83032/1 "2022-06-19T22:20:11Z")

</div>

I know that on working on a package, is common to create a `precompile.jl` file that calls `precompile` for various methods and the types they may accept as arguments, but i was thinking that the same thing could be done for macros too, so they would perform better when generating code or that doesn’t make sense because of how macros work?

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [June 19, 2022, 10:34pm UTC](https://discourse.julialang.org/t/can-macros-also-be-precompiled/83032/2 "2022-06-19T22:34:47Z")

</div>

speaking broadly,  
The most important aspect of Julia macros:  
is that whatever they do, they do before runtime starts

[Imagine writing a macro that changes something so during runtime a distinct flow of control develops; still, it would have completed its work before runtime started.]

Precompiling a macro (at least a more-or-less vanilla macro) would maybe speed the time it takes to do what it does after precompilation and before runtime – the macro would need to be called everywhere in multiple e.g. recurrences to see any difference – if there were any.

Long story short, there are more profitable ways to allocate your focus with respect to macros.

---

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [June 19, 2022, 10:43pm UTC](https://discourse.julialang.org/t/can-macros-also-be-precompiled/83032/3 "2022-06-19T22:43:13Z")

</div>

> [@JeffreySarnoff](#):
>
> would maybe speed the time it takes to do what it does after precompilation and before runtime

That is exactly my doubt, if the precompilation of the macro itself would make it be faster when generating the output code, and not necessary that the output code would be faster.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 19, 2022, 10:51pm UTC](https://discourse.julialang.org/t/can-macros-also-be-precompiled/83032/4 "2022-06-19T22:51:51Z")

</div>

> [@dylanxyz](#):
>
> That is exactly my doubt, if the precompilation of the macro itself would make it be faster when generating the output code, and not necessary that the output code would be faster.

There’s nothing to precompile. They act before compilation.

---

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [June 19, 2022, 10:56pm UTC](https://discourse.julialang.org/t/can-macros-also-be-precompiled/83032/5 "2022-06-19T22:56:49Z")

</div>

I was thinking that because how they work maybe it wouldn’t make sense, but thanks for the answer.
