PERF: remove 10-20ms of work from every page view

<%  s=Time.now;

main_app.categories_path
main_app.guidelines_path
main_app.tos_path
main_app.privacy_path

p (Time.now-s)*1000%>

Returns 10-20ms consistently on i7-4770k, on shared hosts the cost
could easily reach 40ms

This code simply calculates the strings

/categories
/guidelines
/tos
/privacy

It is ludicrous to spend this enormous amount of work just to calculate
4 strings.

I do not know if this is something specific about Discourse or a bug in
Rails (I tried without the main_app prefix and got similar results),
regardless we can got to avoid these _path APIs for now

Discovered this when running a flamegraph on our home page.
This commit is contained in:
Sam 2016-01-21 22:43:56 +11:00
parent 66f9504632
commit 7c5a448f63
2 changed files with 8 additions and 8 deletions

View File

@ -46,10 +46,10 @@
<footer> <footer>
<nav itemscope itemtype='http://schema.org/SiteNavigationElement'> <nav itemscope itemtype='http://schema.org/SiteNavigationElement'>
<a href='<%= path "/" %>'><%= t 'home_title' %></a> <a href='<%= path "/" %>'><%= t 'home_title' %></a>
<%= link_to t('js.filters.categories.title'), main_app.categories_path %> <%= link_to t('js.filters.categories.title'), path("/categories") %>
<%= link_to t('guidelines_topic.title'), main_app.guidelines_path %> <%= link_to t('guidelines_topic.title'), path("/guidelines") %>
<%= link_to t('tos_topic.title'), main_app.tos_path %> <%= link_to t('tos_topic.title'), path("/tos") %>
<%= link_to t('privacy_topic.title'), main_app.privacy_path %> <%= link_to t('privacy_topic.title'), path("privacy") %>
</nav> </nav>
</footer> </footer>
</div> </div>

View File

@ -27,10 +27,10 @@
<footer class="container"> <footer class="container">
<nav itemscope itemtype='http://schema.org/SiteNavigationElement'> <nav itemscope itemtype='http://schema.org/SiteNavigationElement'>
<a href='<%= path "/" %>'><%= t 'home_title' %></a> <a href='<%= path "/" %>'><%= t 'home_title' %></a>
<%= link_to t('js.filters.categories.title'), main_app.categories_path %> <%= link_to t('js.filters.categories.title'), path("/categories") %>
<%= link_to t('guidelines_topic.title'), main_app.guidelines_path %> <%= link_to t('guidelines_topic.title'), path("/guidelines") %>
<%= link_to t('tos_topic.title'), main_app.tos_path %> <%= link_to t('tos_topic.title'), path("/tos") %>
<%= link_to t('privacy_topic.title'), main_app.privacy_path %> <%= link_to t('privacy_topic.title'), path("privacy") %>
</nav> </nav>
<p><%= t 'powered_by_html' %></p> <p><%= t 'powered_by_html' %></p>
</footer> </footer>