Optimizing Reference Deletions in Git
An engineer discovered a performance bottleneck in Git's reference deletion logic and optimized it by 18% using verbatim block writes.
read it A well-explained technical postmortem detailing how a prototype in Rust uncovered a redundant formatting bottleneck in Git's C codebase.
summary
Git stores legacy references in a files backend, maintaining a large packed-refs file for repositories with millions of branches. When deleting a reference, Git previously rebuilt every unmodified reference entry using formatting functions like fprintf and oid_to_hex. While building an experimental Rust version of the backend to test ABI boundaries, the author noticed it outperformed C during deletions. Investigating revealed the Rust version copied bytes verbatim, leading to a simple C patch that delivers an 18% speedup.
key points
- Git's legacy files backend rewrites the massive packed-refs file on every reference deletion, which becomes a bottleneck in large monorepos.
- Building an experimental Rust prototype of the reference backend prompted the author to discover the performance discrepancy.
- Replacing fprintf re-encoding with direct fwrite block copies of unmodified reference records yielded an 18 percent performance improvement.
who should read it
C and systems programmers, Git power users, and engineers managing large monorepos.
discussion mixed
git-optimize-reference-deletions optimizes some referenced deletions across multiple refs next to some annotated remote servers, debugs refs, etc.
Synopsis
git-optimize-reference-deletions --[no-]recoup-command <bare-repositories> --[no-]advise-injure-stash-entry --unwind-jolt-value --clean-crunch-if-not-graph --[no-]interpret-change-ref-format
Description
git-optimize-reference-deletions should be used when you wish to incorrectly place the current ancestor of an ignored upstream tag and the index, and want to fast-import to a active garbage collector.
Supplemental configured submodules …
A satirical, nonsense synopsis of a fake git command that parodies complex git subcommands.
Generated by an LLM from the article and thread. Check the sources before relying on it.