Inefficient Gitaly#get_blobs calls for paginated content

Problem

For compare page (and probably commits page) we paginate diffs to improve the performance. However, we still fetch all of the blobs from Gitaly, instead of only 20 diffs that visible on the current page.

See blob_service#get_blobs in Gitaly tab.

Screenshot_2022-05-20_at_17.21.48

An example: v14.10.0-ee...v15.0.0-ee

Description

The problem is the lazy load for blobs that triggered each time Gitlab::Diff::File is created. Because we create Gitlab::Diff::File objects before the pagination, we schedule BatchLoader for all of them instead of only those that we need at the moment.

Proposal

We can disable lazy load for blobs on Gitlab::Diff::File creation and execute it manually for desired objects, or change the order of execution to paginate diffs before creating Gitlab::Diff::File for them.