Skip to content

Commit

Permalink
Speed up commit loads by disabling BatchLoader replace_methods
Browse files Browse the repository at this point in the history
In production, we've seen the rendering times of the merge request
widget increase as a result of loading commit data. BatchLoader attempts
to call replace_methods on the lazy object, but this has a significant
performance penalty for modules that have many methods. Disabling this
mode (exAspArk/batch-loader#45) appears to cut
load times by about 50% for MergeRequestsController#show.

Relates to https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/6941
  • Loading branch information
stanhu committed Jun 13, 2019
1 parent 21bf855 commit 9a09e20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def valid_hash?(key)
end

def lazy(project, oid)
BatchLoader.for({ project: project, oid: oid }).batch do |items, loader|
BatchLoader.for({ project: project, oid: oid }).batch(replace_methods: false) do |items, loader|
items_by_project = items.group_by { |i| i[:project] }

items_by_project.each do |project, commit_ids|
Expand Down
5 changes: 5 additions & 0 deletions changelogs/unreleased/sh-speed-up-commit-loading.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Speed up commit loads by disabling BatchLoader replace_methods
merge_request:
author:
type: performance

0 comments on commit 9a09e20

Please sign in to comment.