Skip to content

Use Gitaly binary flag to check for binary diffs

What does this MR do and why?

This MR significantly speeds up diffs rendering by skipping binary checks. Instead, it reuses the binary flag coming straight from Git.

Current process

  1. Fetch diffs from Gitaly (DB for MRs)
  2. Check if both blobs are binary for each diff path
  3. Fetch old and new blobs from Gitaly
  4. Put each file as a whole (up to 1MB of data) through a charlock_holmes gem to see if it is a binary file
  5. Decide how to render a diff based on the binary flag

New process

  1. Fetch diffs from Gitaly (DB for MRs)
  2. Check binary flag from Gitaly for each diff path
  3. Decide how to render a diff based on the binary flag

Screenshots

Before After
image image

How to set up and validate locally

  1. Enable rapid_diffs and rapid_diffs_on_mr_show
  2. Apply this patch:
    diff --git a/app/presenters/rapid_diffs/base_presenter.rb b/app/presenters/rapid_diffs/base_presenter.rb
    --- a/app/presenters/rapid_diffs/base_presenter.rb	(revision 4c1b8a9c15a470c430848765a2159e887bad1f32)
    +++ b/app/presenters/rapid_diffs/base_presenter.rb	(date 1751463318158)
    @@ -50,7 +50,7 @@
     attr_reader :request_params
    
         def offset
    -      5
    +      500
         end
     
         private
    **
  3. Go to a merge request with many changed files (more than 100)
  4. Select 'Changes' tab
  5. Add ?rapid_diffs=true to the URL, follow it
  6. Measure performance using performance bar
  7. Observe a significant decrease to CharlockHolmes gem
Edited by Stanislav Lashmanov

Merge request reports

Loading