class UserHandler
end
macro register(cls)
  %k = ""
  {% for c, index in cls.stringify.chars %}
    {% if index != 0 && c.stringify =~ /[A-Z]/ %}
      %k += "_" + {{c}}
    {% else %}
      %k += {{c}}
    {% end %}
  {% end %}
  %k.downcase
end
register UserHandler # -> "user_handler"
Play code: https://play.crystal-lang.org/#/r/72ws
I know that %k is a runtime variable, and my requirements can actually be done at compile time. How can I avoid this kind of overhead?
