Can macros also be precompiled?

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?

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.

1 Like

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.

2 Likes

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