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
- Fetch diffs from Gitaly (DB for MRs)
- Check if both blobs are binary for each diff path
- Fetch old and new blobs from Gitaly
- Put each file as a whole (up to 1MB of data) through a
charlock_holmes
gem to see if it is a binary file - Decide how to render a diff based on the binary flag
New process
- Fetch diffs from Gitaly (DB for MRs)
- Check binary flag from Gitaly for each diff path
- Decide how to render a diff based on the binary flag
Screenshots
Before | After |
---|---|
![]() |
![]() |
How to set up and validate locally
- Enable
rapid_diffs
andrapid_diffs_on_mr_show
- 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 **
- Go to a merge request with many changed files (more than 100)
- Select 'Changes' tab
- Add
?rapid_diffs=true
to the URL, follow it - Measure performance using performance bar
- Observe a significant decrease to CharlockHolmes gem
Edited by Stanislav Lashmanov