idi527
Continuing the discussion from Performance - Best practices?
If they are iolists, then why do function_from_file in eex return binaries? https://github.com/idi-ot/eex_test
iex(1)> EExTest.fortune_html [a: "a", b: "b"]
"<!DOCTYPE html>\n<html>\n <head>\n <title>Fortunes</title>\n </head>\n <body>\n <table>\n <tr><th>id</th><th>message</th></tr>\n \n <tr><td>a</td><td>a</td></tr>\n \n <tr><td>b</td><td>b</td></tr>\n \n </table>\n </body>\n</html>\n"
I would’ve expected something like this
iex(3)> EExTest.custom_fortune_html [a: "a", b: "b"]
["<!DOCTYPE html>\n<html>\n <head>\n <title>Fortunes</title>\n </head>\n <body>\n <table>\n <tr><th>id</th><th>message</th></tr>\n",
["<tr><td>", "a", "</td><td>", "a", "</td></tr>", "<tr><td>", "b", "</td><td>",
"b", "</td></tr>"], " </table>\n </body>\n</html>\n"]
Some tests
# render small list
iex(6)> :timer.tc(fn -> Enum.each(1..100_000, fn _ -> EExTest.fortune_html([a: "a", b: "b"]) end) end)
{480068, :ok}
iex(7)> :timer.tc(fn -> Enum.each(1..100_000, fn _ -> EExTest.custom_fortune_html([a: "a", b: "b"]) end) end)
{279135, :ok}
# render empty list
iex(10)> :timer.tc(fn -> Enum.each(1..100_000, fn _ -> EExTest.fortune_html([]) end) end)
{144888, :ok}
iex(11)> :timer.tc(fn -> Enum.each(1..100_000, fn _ -> EExTest.custom_fortune_html([]) end) end)
{74700, :ok}
# render bigger list
iex(12)> data = Enum.map(1..1000, fn i -> {i, i} end)
iex(14)> :timer.tc(fn -> Enum.each(1..1_000, fn _ -> EExTest.custom_fortune_html(data) end) end)
{277821, :ok}
iex(15)> :timer.tc(fn -> Enum.each(1..1_000, fn _ -> EExTest.fortune_html(data) end) end)
{1078125, :ok}
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
:warning: Security advisory: Decimal DoS vulnerability
A vulnerability has been published for decimal where very large exponents can cau...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes.
We’re a small ...
New
Other Trending Topics
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
OvermindDL1
I think it depends on the specific engine you use. I think the SmartEngine concats a big binary blob (should be an iolist in my opinion, but someone else could always make a new engine to do so). EEx itself is just the parser stuff.
idi527
Oh, I see. I meant the default one. I wonder if the benchmarked apps use any other engine that emits iolists? That’d be a considerable improvement in IO throughput, I think.
Is there any engine that compiles templates to iolists?
OvermindDL1
Honestly I’ve not actually looked… ^.^;
idi527
Yeah, it doesn’t seem too hard to write one. That’s a naive implementation where I just replaced empty strings with empty lists and string concatenation with list building.
idi527
Yes, that’s what it does. elixir/lib/eex/lib/eex/engine.ex at v1.5.2 · elixir-lang/elixir · GitHub
But phoenix uses
Phoenix.HTML.Enginewhich does use iolists. phoenix_html/lib/phoenix_html/engine.ex at main · phoenixframework/phoenix_html · GitHubOvermindDL1
Ah good to know, I ‘thought’ it did but was not certain.
idi527
But they are still slower …
OvermindDL1
Are you doing everything it does? They do things like auto-escaping of text so no html injections and such, lookups for values in different places, etc… etc…
idi527
That happens at compile time, doesn’t it?
Reading through phoenix_html again, I see that some of the checks are done at runtime though, yeah.
OvermindDL1
How would it? Say some user input is in a variable that is put into the template, it needs to escape that, thus a runtime call, it has all kinds of checks all over (because, for example, it shouldn’t escape that user variable if it is wrapped in a
:raw2-tuple).