b02458ef52
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 * UserEntity * Kaminari::Helpers::Paginator * CurrentUserEntity * ActionView::Base * ActionDispatch::DebugExceptions::DebugView * MarkupHelper * MergeRequestPresenter After this change: * Kaminari::Helpers::Paginator * ActionView::Base * ActionDispatch::DebugExceptions::DebugView Each time a partial is rendered for the first time, all methods for those modules will have to be redefined. This can exact a significant performance penalty. How bad is this penalty? Using the following benchmark script, we can use DTrace to sample the Ruby interpreter: ``` Benchmark.bm do |x| x.report do 1000.times do ActionView::CompiledTemplates.module_eval("def testme\nend") end end end ``` This revealed a 11x jump in the time spent in `core#define_method` alone. Rails 6 fixes this behavior by moving the `include CompiledTemplates` into ActionView::Base so that including `ActionView::Context` doesn't quietly affect other modules in this way. Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/11198 |
||
---|---|---|
.. | ||
projects | ||
accounts_helper.rb | ||
active_sessions_helper.rb | ||
appearances_helper.rb | ||
application_helper.rb | ||
application_settings_helper.rb | ||
auth_helper.rb | ||
auto_devops_helper.rb | ||
avatars_helper.rb | ||
award_emoji_helper.rb | ||
blame_helper.rb | ||
blob_helper.rb | ||
boards_helper.rb | ||
branches_helper.rb | ||
breadcrumbs_helper.rb | ||
broadcast_messages_helper.rb | ||
builds_helper.rb | ||
button_helper.rb | ||
calendar_helper.rb | ||
ci_status_helper.rb | ||
ci_variables_helper.rb | ||
clusters_helper.rb | ||
commits_helper.rb | ||
compare_helper.rb | ||
components_helper.rb | ||
conversational_development_index_helper.rb | ||
cookies_helper.rb | ||
count_helper.rb | ||
dashboard_helper.rb | ||
defer_script_tag_helper.rb | ||
deploy_tokens_helper.rb | ||
diff_helper.rb | ||
dropdowns_helper.rb | ||
emails_helper.rb | ||
emoji_helper.rb | ||
environment_helper.rb | ||
environments_helper.rb | ||
events_helper.rb | ||
explore_helper.rb | ||
favicon_helper.rb | ||
form_helper.rb | ||
git_helper.rb | ||
gitlab_routing_helper.rb | ||
graph_helper.rb | ||
groups_helper.rb | ||
hooks_helper.rb | ||
icons_helper.rb | ||
ide_helper.rb | ||
import_helper.rb | ||
instance_configuration_helper.rb | ||
issuables_helper.rb | ||
issues_helper.rb | ||
javascript_helper.rb | ||
kerberos_spnego_helper.rb | ||
labels_helper.rb | ||
lazy_image_tag_helper.rb | ||
markup_helper.rb | ||
mattermost_helper.rb | ||
members_helper.rb | ||
merge_requests_helper.rb | ||
milestones_helper.rb | ||
milestones_routing_helper.rb | ||
mirror_helper.rb | ||
namespaces_helper.rb | ||
nav_helper.rb | ||
notes_helper.rb | ||
notifications_helper.rb | ||
numbers_helper.rb | ||
page_layout_helper.rb | ||
pagination_helper.rb | ||
performance_bar_helper.rb | ||
pipeline_schedules_helper.rb | ||
preferences_helper.rb | ||
profiles_helper.rb | ||
projects_helper.rb | ||
repository_languages_helper.rb | ||
rss_helper.rb | ||
runners_helper.rb | ||
safe_params_helper.rb | ||
search_helper.rb | ||
selects_helper.rb | ||
services_helper.rb | ||
sidekiq_helper.rb | ||
snippets_helper.rb | ||
sorting_helper.rb | ||
storage_helper.rb | ||
submodule_helper.rb | ||
system_note_helper.rb | ||
tab_helper.rb | ||
tags_helper.rb | ||
time_helper.rb | ||
todos_helper.rb | ||
tree_helper.rb | ||
triggers_helper.rb | ||
user_callouts_helper.rb | ||
users_helper.rb | ||
version_check_helper.rb | ||
visibility_level_helper.rb | ||
webpack_helper.rb | ||
wiki_helper.rb | ||
workhorse_helper.rb |