Go to content

Andrew Selder - Speeding up dynamic templates Using Meta-programming

Leave comments at: https://elixirforum.com/t/elixirconf-2023-andrew-selder-speeding-up-dynamic-templates-using-meta-programming/59013 Many applications have the need for users to define their templates (multi-tenant eCommerce, CMSs, etc.). Phoenix has a reputation for lightning-quick template rendering, but performance is quite lacking if you ever try to render a template not defined at compile time. At Estée Lauder, we found simple product grids take 400-500ms to render as we had to repeatedly render a brand-specific template to display the products. Using Elixir's ability to metaprogram, we developed a way to get compiled-template-level performance for arbitrary dynamic templates. Benchee showed improvements of over 300x when using our new method. ``` # Comparison: # new black magic 8.33 M # old way 0.0249 M - 334.37x slower +40.04 μs ``` In this talk, we'll review the basics of meta-programming and hopefully de-mystify it and make it more approachable. Then, we'll explore how we used these techniques to deliver blazing-fast performance for our customers.

September 5, 2023