Looking to understand the difference between `Phoenix.HTML.Engine` and `EEx.SmartEngine`

I have been experimenting with the Phoenix.HTML.Engine for a templating layer.

My question involves the following code.

require EEx
EEx.function_from_file(:defp, :view, file_path, [:assigns], engine: Phoenix.HTML.Engine)

Calling this macro will create a view/1 function. I assumed the only difference when using this engine (instead of the default EEx.SmartEngine) would be that html was properly escaped.

However the smart engine returns a binary but the phoenix html engine returns an io_list.

The source of this difference can be traced back to the following code

vs

I believe that returning an io_list is more performant because new binaries do not have to be allocated.
If that is the case is there and argument to be made that the standard EEx engine should also return an io_list to benefit from the same performance improvement?

2 Likes

I wondered that myself some time ago. Do EEx templates compile to iolists or binaries?

But people are more used to binaries than to iolists, I think. It would probably be too confusing for some.

It would be great though if more projects knew about this and used iolists underneath instead of binaries.

1 Like

Phoenix aims to be beginner friendly? Does it not run the risk of confusing people.

Also thanks for linking to that thread very interesting. I can see myself implementing my own engine. I would use phoenix_html but I don’t need the form helpers and plug is another large dependency i don’t need

1 Like

Yeah, it turned out to be rather easy. At least for my use case.

Phoenix aims to be beginner friendly?

I think it does.

Does it not run the risk of confusing people.

When using EEx with phoenix html engine with phoenix, I don’t think many people wonder how it works, they just their templates to be “fast”. But EEx default engine is used in many other ways as well, to generate configs for example. And there is no real need for it to be fast, it’s more important to be intuitive.

1 Like