libgit2/libgit2 — pull request #1781 by brodie (2013-08-13 18:07:36+00:00)
Title: fileops: stat() before open()ing in git_futils_readbuffer_updated()

This reverts refactoring done in 13224ea4aad9a1b3c9cc4c992ceaea9af623e047 that introduces a performance regression for NFS when reading files that don't exist. open() forces a cache invalidation on NFS, while stat()ing a file just uses the cache and is very quick.

To give a specific example, say you have a repo with a thousand packed refs. Before this change, looking up every single one would incur a thousand slow open() calls (to check for loose refs). With this change, it's a thousand fast stat() calls.

Aside: It's unfortunate that looking up a packed ref forces libgit2 to check for a loose ref on disk. But it seems Git's own semantics are to prefer loose refs over packed refs, so I'm not sure that can be avoided.