Skip to content
  • Stan Hu's avatar
    Fix slow performance with compiling HAML templates · b02458ef
    Stan Hu authored
    In Rails 5, including `ActionView::Context` can have a significant and
    hidden performance penalty because this module also includes
    `ActionView::CompiledTemplates`. This means that any module that
    includes ActionView::Context becomes a descendant of
    `CompiledTemplates`.
    
    When a partial is rendered for the first time, it runs
    `ActionView::CompiledTemplates#module_eval`, which will evaluate a
    string that defines a new method for that partial. For example, the
    source of partial might be this string:
    
    ```
    def _app_views_project_show_html_haml___12345(local_assigns, output)
      "hello world"
    end
    ```
    
    When this string is evaluated, the Ruby interpreter will define the
    method and clear the global method cache for all descendants of
    `ActionView::CompiledTemplates`. Previous to this change, we
    inadvertently made a number of modules fall into this category:
    
    * GroupChildEntity
    * NoteUserEntity
    * Notify
    * MergeRequestUserEntity
    * AnalyticsCommitEntity
    * CommitEntity
    *...
    b02458ef