A Rust experiment uncovers an 18% speedup in Git reference deletion
Optimizing Reference Deletions in Git
Git's files backend rewrites the entire packed-refs file on every deletion, which can be gigabytes in large monorepos. While benchmarking a Rust rewrite of the backend against the C original, the author noticed the Rust version was faster. The C code was needlessly reformatting untouched references with fprintf and oid_to_hex; writing them verbatim with fwrite instead cut deletion time by about 18%. The patch is now merged and ships in Git v2.98.
The C version iterates through the references and writes any unmodified reference to the 'packed-refs' file. But unlike the Rust version, which writes it verbatim, it calls write_packed_entry().