Skip to content

Update BatchLoader gem and use replace_methods: false for Avatarable

In https://gitlab.com/gitlab-org/gitlab-ce/issues/60373#note_159582633 and https://gitlab.com/gitlab-org/gitlab-ce/issues/43065#note_160469960, we see profiles with a lot of time in BatchLoader#__replace_with!. This defines methods on the batch loader that proxy to the 'real' object using send. The alternative is method_missing, which is slower.

However, we've noticed that method_missing can be faster if:

  1. The objects being loaded have a large interface.
  2. We don't call too many methods on the loaded object.

This will vary case-by-case. One case where we are reasonably confident that this will help is https://gitlab.com/gitlab-org/gitlab-ce/blob/v11.10.0/app/models/concerns/avatarable.rb#L94, because uploads meet both criteria above.

https://github.com/exAspArk/batch-loader/issues/43 proposes a new replace_methods keyword argument for BatchLoader to allow us to turn this off. Once that has been implemented in BatchLoader, we should:

  1. Update to use that version of BatchLoader.
  2. Use replace_methods: false in Avatarable#retrieve_upload_from_batch.
  3. Measure the results!