---
title: "Optimizing Git’s Merge Machinery, #3"
description: "Git's merge machinery can skip rename detection for source files whose renames cannot change the merge result: files unmodified on the unrenamed side of history, and files not needed for directory rename detection's majority rule."
url: "https://swe.quest/articles/optimizing-git-s-merge-machinery-3-2b68eed913acded5"
canonical: "https://blog.palantir.com/optimizing-gits-merge-machinery-3-2dc7c7436978"
source: "Palantir"
published: "2021-04-09"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 11
tags: ["version-control","performance","algorithms","open-source"]
---

# Optimizing Git’s Merge Machinery, #3

A post on [Palantir](https://swe.quest/sources/palantir.md), published 2021-04-09, 11 min read, Deep dive. Original: [https://blog.palantir.com/optimizing-gits-merge-machinery-3-2dc7c7436978](https://blog.palantir.com/optimizing-gits-merge-machinery-3-2dc7c7436978)

## Summary

Git's merge machinery can skip rename detection for source files whose renames cannot change the merge result: files unmodified on the unrenamed side of history, and files not needed for directory rename detection's majority rule. Exploiting this meant pushing three-commit merge context across the old diff/rename-detection abstraction boundary, which only knew about two trees. For a typical cherry-pick touching ~10 files against 5K upstream renames, the comparison matrix shrinks from 5K×5K to ~10×5K. The mega-renames testcase drops from 130s to 11.4s on top of basename-guided detection, or from 1800s to 16s alone. The change ships in git 2.32.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Version control](https://swe.quest/tags/version-control.md) (Engineering practices)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)
- [Open source](https://swe.quest/tags/open-source.md) (Engineering practices)

## Prerequisites

- git object model and blob hashes
- three-way merge
- git rename detection

## Keywords

Git, merge-ort, rename detection, directory rename detection, git 2.32

## Related posts

- [Scaling merge-ort across GitHub](https://swe.quest/articles/scaling-merge-ort-across-github-6d05304b446e2f08.md): GitHub Engineering · 2023-07-27 · Medium · 5 min read · Version control, Performance engineering, Deployment
  GitHub replaced its libgit2-based server-side merge and rebase implementation with Git's merge-ort strategy, which needs no working directory and matches what the Git command line does.
- [Improve Git monorepo performance with a file system monitor](https://swe.quest/articles/improve-git-monorepo-performance-with-a-file-system-monitor-1e7445f19bf20b0e.md): GitHub Engineering · 2022-06-29 · Medium · 22 min read · Version control, Performance engineering, Developer tools
  Git 2.37.0 adds a builtin file system monitor daemon (\`git fsmonitor--daemon\`) for macOS and Windows, enabled by setting \`core.fsmonitor\` to true.
- [Merging two GitHub repositories without losing commit history](https://swe.quest/articles/merging-two-github-repositories-without-losing-commit-history-7428e9ac84244059.md): Mozilla Hacks · 2022-08-29 · Medium · 15 min read · Version control, Developer tools
  MDN merged small example repositories into a larger parent repo while keeping full commit history, using only plain git commands.
- [Scaling Git’s garbage collection](https://swe.quest/articles/scaling-git-s-garbage-collection-9458d212eaaeddf6.md): GitHub Engineering · 2022-09-13 · Hard · 23 min read · Version control, Storage engines, Memory management, Scaling
  Git's garbage collection historically stored recently-written unreachable objects as individual loose files so their mtimes could govern expiry, which bloated storage, exhausted inodes and slowed repacks in busy repositories at GitHub's 18.6 PB scale.
- [User-defined functions in ClickHouse Cloud](https://swe.quest/articles/user-defined-functions-in-clickhouse-cloud-33c541eadcfd2cd4.md): ClickHouse · 2022-12-08 · Medium · 6 min read · SQL, Analytics & OLAP, Version control
  ClickHouse SQL user-defined functions, now available in ClickHouse Cloud, can reconstruct a file's full commit history across renames in git-import data.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
