使用 link 和辅助函数,Phoenix 模板呈现缓慢

Phoenix template rendering slow with link and helper functions

我发现使用 link 函数和生成的路径辅助函数的渲染模板速度很慢。

比如我运行mix phoenix.gen.html Author authors name:string

里面index.html.eex

<%= for author <- @authors do %> # ... <%= link "Show", to: author_path(@conn, :show, author) %> <% end %>

1500条作者记录响应时间超过2秒。但是,如果我用author_path注释掉上面的link函数,响应时间只有9毫秒。两种情况下的数据库查询时间都是相同的 (4ms)。

我尝试删除 link 并只打印 author_path(@conn, :show, author)。这有帮助,但响应时间仍然超过 500 毫秒。

感谢您就如何找到性能缓慢的根源提供任何建议。

这是因为在 Elixir 1.2 之前的开发中没有整合协议。您会发现,如果您 运行 在产品中,您的渲染速度会很快。如果你跳上 Elixir 1.2,协议总是被整合,即使在开发中也是如此。