Compiling files with many function heads is very slow(OTP 26 issue?)

Thanks, took a quick look, does not look as complex as what I’m doing, getting good speed while working on binaries is hard especially when you want to parse unicode, but it just really weird how the compiler could figure out to create a jump table from:

defmodule Test do
  require Unicode.Set
  case_ast =
    for c <- Unicode.Set.to_pattern!("[[:Lu:], [:Ll:], [:Lt:], [:Lm:], [:Lo:], [:Nl:], [:Mn:], [:Mc:], [:Nd:], [:Pc:], [:Cf:]]") do
      hd(
        quote do
          <<unquote(c), _::binary>> -> true
        end
      )
    end ++ quote do
      _ -> false
    end

  def case_fn(binary) do
    case binary do
      unquote(case_ast)
    end
  end

  def guard_fn(<<b::utf8, _::binary>>) when Unicode.Set.match?(b, "[[:Lu:], [:Ll:], [:Lt:], [:Lm:], [:Lo:], [:Nl:], [:Mn:], [:Mc:], [:Nd:], [:Pc:], [:Cf:]]"), do: true
  def guard_fn(_binary), do: false
end

But as soon as you throw in a function then it just capitulate.

1 Like