Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Palantir 11 min read Deep dive hardMaster

Optimizing Git’s Merge Machinery, #3

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.

Assumes: git object model and blob hashesthree-way mergegit rename detection

Related posts

  • Scaling merge-ort across GitHub

    GitHub Engineering mediumAdept

    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. Both changes were validated with Scientist experiments that ran old and new code paths side by side in production. For merges, P50 dropped from about 71 ms to under 8 ms and P99 from 1.63 s to about 330 ms, a 10x speedup on the github/github monolith. Rebases moved to the new git-replay subcommand, and in testing they took under 10 minutes of compute versus 2.56 hours with libgit2.

  • Improve Git monorepo performance with a file system monitor

    GitHub Engineering mediumAdept

    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. The daemon registers for OS change notifications and keeps an in-memory, time-sorted queue of changed paths. Git commands query it over IPC using tokens that carry the daemon PID and a resync ID, so dropped events trigger a safe full rescan. Combined with `core.untrackedcache`, it cuts `git status` on Chromium and synthetic 1M/2M-file worktrees from 17–85 seconds to under one second by shrinking the refresh_index and untracked-file phases, which also speeds up `git diff`, `git add` and `git checkout`.

  • Merging two GitHub repositories without losing commit history

    Mozilla Hacks mediumAdept

    MDN merged small example repositories into a larger parent repo while keeping full commit history, using only plain git commands. First, inside the source repo, all files move into a subdirectory matching the target layout (using zsh extendedglob negation like `mv ^(sw-test|service-worker)`, with hidden files moved separately so `.git` stays put). That change is merged, then the source is added as a remote in the target and merged with `git merge --allow-unrelated-histories`, resolving add/add conflicts such as README.md.

  • Scaling Git’s garbage collection

    GitHub Engineering hardMaster

    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. Cruft packs fix this by packing unreachable objects together with a companion .mtimes file holding a 4-byte per-object timestamp, indexed via the pack index, so individual objects can be freshened and expired independently. The --prune=<date> grace period exists to mitigate a race where a concurrent push makes a to-be-deleted object reachable, and cruft pack generation walks reachability to separate reachable from unreachable objects while expiring unreachable clusters all-or-nothing. The work was contributed upstream to Git.

  • User-defined functions in ClickHouse Cloud

    ClickHouse mediumAdept

    ClickHouse SQL user-defined functions, now available in ClickHouse Cloud, can reconstruct a file's full commit history across renames in git-import data. ClickHouse lacks recursive CTEs and UDFs cannot recurse, so the workaround chains six UDFs that each call the next. Each one looks up the file's previous path from Rename/Add rows and appends it to an array, which caps the rename depth at five. The resulting array then filters the history with `path IN file_path_history(...)`. Fixing the data at insert time with a stable file ID is noted as the cleaner alternative.

The quest for software engineering knowledge.

Look:
Layout: