You are probably having the same issue as Phoenix.
If you invoke too many macros that inject variables in the module body, you easily end-up with thousands of variables in the module body and the Erlang compiler down the stack is going to choke on it (they use a linear data structure, it is a story for another day).
The way we fixed this issue in Phoenix is to ensure the variables do not leak. For example, let's suppose your macro is outputing this code:
a = do_this
b = do_that
c = and_that
If you make it output this code:
(fn ->
a = do_this
b = do_that
c = and_that
end).()
The problem should disappear. If you are calling the same code multiple times with different arguments, you can even define a function once and just pass the multiple arguments. Again, that's what we did with Phoenix:
I hope this gives some direction. If not, please send me a command I can run in order to reproduce the issue but that doesn't take 7 minutes. :)