edgurgel / solid

Liquid template engine in Elixir
https://hexdocs.pm/solid
MIT License
207 stars 39 forks source link

Compilation Performance when adding Custom Tags #131

Open atonse opened 12 months ago

atonse commented 12 months ago

Thank you for this awesome library, we love it 😄

We've noticed that when we add custom tags (of which we've added 8) it slows down our compiles tremendously when processing those tags. So just the tags take about 20 seconds to compile.

Do you know if this is this something that's just a limitation of nimble_parsec and some kind of Big(O) issue with the underlying algorithms or potentially how we're constructing our tags that's resulting in way more parser combinations than needed?

Here's an example of a custom tag:

In Liquid it is:

{% image file_id %}

The elixir:

  @impl true
  def spec(_parser) do
    space = Literal.whitespace(min: 0)

    ignore(BaseTag.opening_tag())
    |> ignore(space)
    |> ignore(string("image"))
    |> ignore(space)
    |> tag(Argument.argument(), :file_id)
    |> ignore(space)
    |> ignore(BaseTag.closing_tag())
  end
edgurgel commented 4 months ago

Yeah the parser is quite complex and to keep it fast we avoid using lots of "defcombinators". But it's something we can revisit once we have a proper set of benchmarks :thinking:.