gogs / git

Package GoGits - Git is a pure Go implementation of Git manipulation.
Apache License 2.0
176 stars 32 forks source link

Avoid parsing index files more than once #4

Closed Schnouki closed 10 years ago

Schnouki commented 10 years ago

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.

unknwon commented 10 years ago

Great thanks!