arizona-framework / arizona

A web framework for Erlang/OTP
Apache License 2.0
7 stars 1 forks source link

Speed up render by storing compiled templates #150

Open williamthome opened 3 months ago

williamthome commented 3 months ago

We had an attempt to speed up the render of the templates by storing it in persistent_term here, but it was not working as expected, as related in #135. Maybe a module that holds an ETS table could be implemented to keep them in memory.

The current flow is:

  1. The client requests a page
  2. The module of the route is called to render a template
  3. That template is scanned, parsed, compiled, and, finally, rendered
  4. The client connects to the server via WebSocket
  5. The WebSocket requests the same template to be rendered
  6. That template again is scanned, parsed, compiled, and, finally, rendered
  7. The client receives the metadata and, finally, is good to go

In steps 3 and 6, we should be able to just fetch and render the compiled template.

Suggestions welcome.

williamthome commented 3 months ago

Another option is to compile the template into a new module via the Erlang compile module. Zotonic uses this approach in its template_compiler.

williamthome commented 3 months ago

Another one is to use ct_expand, which expands the result at the compile time.