gogits/git — pull request #4 by Schnouki (2014-07-22 17:34:47+00:00)
Title: Avoid parsing index files more than once

In huge repositories, `readIdxFile()` can be quite slow. Since all index files are already read by `OpenRepository()`, it's useless to re-parse them when they are needed: we can just re-use what was read the first time.

I noticed this in a program I'm writing, that is essentially iterating over all the objects in the last commit of a specific branch. There are several thousands of objects in several hundreds of subtrees. On my underpowered ARM NAS, this was extremely slow: 2380 seconds on average. `go tool pprof` showed that about 90% of that time was spent in `readIdxFile()`. With this patch, the execution only takes 140 seconds on average.