Avoid recompiling macros

I have not worked much with macros but I’m trying to use them in this billion row challenge. This particular macro generates 200k functions to pattern match on input strings with a variety of substring matches. It works pretty well but every time I make a change elsewhere in the program it’s taking FOREVER to recompile. Any suggestions on how to just compile the macros once and then pull the resulting functions into the larger project?

What you are seeing probably isn’t the time taken to compile the macro, its the time taking to compile the code generated by the macro when its invoked.

The time to compile multiple function heads for the same function goes up exponentially when the number of function heads reaches a “large” number. In my experience that means when it’s over several hundred function heads, compilation starts to slow down quite a lot - and get exponentially worse after that…

Note that this isn’t Elixir compilation - its somewhere in BEAM code generation or optimisation.

2 Likes