[PR #53] [MERGED] Faster commit lookup #61

Closed
opened 2026-02-16 10:23:59 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-gitea/git/pull/53
Author: @ethantkoenig
Created: 5/22/2017
Status: Merged
Merged: 5/26/2017
Merged by: @lunny

Base: masterHead: commit_lookup


📝 Commits (8)

📊 Changes

4 files changed (+197 additions, -95 deletions)

View changed files

📝 .gitignore (+2 -0)
📝 Makefile (+6 -2)
📝 tree_entry.go (+125 -93)
tree_entry_test.go (+64 -0)

📄 Description

A faster implementation of GetCommitsInfo, addresses https://github.com/go-gitea/gitea/issues/491 and https://github.com/go-gitea/gitea/issues/502.

The previous implementation made a call to git log for each entry, each of which required scanning through the commit history. This new implementation instead makes a single call to git log. This is faster, because it involves scanning the commit history only once.

BENCHMARK RESULTS:
Shoutout to @sapk for the benchmark tests he wrote (#54), which I have stolen here.

Old implementation:

BenchmarkEntries_GetCommitsInfo/gitea-4         	     200	  70670229 ns/op
BenchmarkEntries_GetCommitsInfo/manyfiles-4     	       1	35907609610 ns/op
BenchmarkEntries_GetCommitsInfo/moby-4          	      50	 204585469 ns/op
BenchmarkEntries_GetCommitsInfo/go-4            	      20	 640497304 ns/op
BenchmarkEntries_GetCommitsInfo/linux-4         	      20	 829981474 ns/op

New implementation:

BenchmarkEntries_GetCommitsInfo/gitea-4         	     500	  34284443 ns/op
BenchmarkEntries_GetCommitsInfo/manyfiles-4     	      30	 424753714 ns/op
BenchmarkEntries_GetCommitsInfo/moby-4          	     100	 109430547 ns/op
BenchmarkEntries_GetCommitsInfo/go-4            	      30	 521336982 ns/op
BenchmarkEntries_GetCommitsInfo/linux-4         	      20	 813171326 ns/op

IMPLEMENTATION DETAILS:
Gets the 16 latest commits affecting the relevant entries (git log --name-only -16 HEAD -- <treePath>). The output of this command containing which files were affect by each commit. Scan through this list of cmmit, and stop once a commit has been found for each entry.

If you go through the first batch of 16 commits, you get then next 32 commits (git log --name-only -32 <last-commit-from-first-batch>^ -- entry1 entry2 ...); each time you double the number of commits. This ensures that in the common case you'll only have to read in a small number (16) of commits, but you also won't have to make too many calls to git log if you need to go further into the commit history.

Finally, if you are looking for 32 or fewer entries, manually list out each entry in the git log command (git log --name-only -- entry1 entry2...) to support a more targeted search.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-gitea/git/pull/53 **Author:** [@ethantkoenig](https://github.com/ethantkoenig) **Created:** 5/22/2017 **Status:** ✅ Merged **Merged:** 5/26/2017 **Merged by:** [@lunny](https://github.com/lunny) **Base:** `master` ← **Head:** `commit_lookup` --- ### 📝 Commits (8) - [`c84e4aa`](https://github.com/go-gitea/git/commit/c84e4aadc2c4f84180e2e8dfa1a14efcd3b4e949) Add bench task - [`96af092`](https://github.com/go-gitea/git/commit/96af092d0061ef75fad6305004125b9c127c8e6c) Create tree_entry_test.go - [`eef76cd`](https://github.com/go-gitea/git/commit/eef76cd15f9b53939dcd192e1fd1950ae1cbd46f) Remove init time - [`ae8ee36`](https://github.com/go-gitea/git/commit/ae8ee3619290061ddc67e44c78dd3b25431c0050) Add TODO information - [`dcfda73`](https://github.com/go-gitea/git/commit/dcfda73c5de1701141f148fa920fc84eb9026578) Add linux repo - [`76cec74`](https://github.com/go-gitea/git/commit/76cec74c94b04c16ce0edb24cc946721cb4506d3) Faster implementation of GetCommitsInfo - [`e8bc37c`](https://github.com/go-gitea/git/commit/e8bc37c40f4293f9e5120bb0d465e610d73949a3) Start/stop timer - [`f22ce90`](https://github.com/go-gitea/git/commit/f22ce901b067462cfb039144a7486687a1278121) Use benchmark/ directory for benchmark repos ### 📊 Changes **4 files changed** (+197 additions, -95 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+2 -0) 📝 `Makefile` (+6 -2) 📝 `tree_entry.go` (+125 -93) ➕ `tree_entry_test.go` (+64 -0) </details> ### 📄 Description A faster implementation of `GetCommitsInfo`, addresses https://github.com/go-gitea/gitea/issues/491 and https://github.com/go-gitea/gitea/issues/502. The previous implementation made a call to `git log` for each entry, each of which required scanning through the commit history. This new implementation instead makes a single call to `git log`. This is faster, because it involves scanning the commit history only once. __BENCHMARK RESULTS__: Shoutout to @sapk for the benchmark tests he wrote (#54), which I have stolen here. Old implementation: ``` BenchmarkEntries_GetCommitsInfo/gitea-4 200 70670229 ns/op BenchmarkEntries_GetCommitsInfo/manyfiles-4 1 35907609610 ns/op BenchmarkEntries_GetCommitsInfo/moby-4 50 204585469 ns/op BenchmarkEntries_GetCommitsInfo/go-4 20 640497304 ns/op BenchmarkEntries_GetCommitsInfo/linux-4 20 829981474 ns/op ``` New implementation: ``` BenchmarkEntries_GetCommitsInfo/gitea-4 500 34284443 ns/op BenchmarkEntries_GetCommitsInfo/manyfiles-4 30 424753714 ns/op BenchmarkEntries_GetCommitsInfo/moby-4 100 109430547 ns/op BenchmarkEntries_GetCommitsInfo/go-4 30 521336982 ns/op BenchmarkEntries_GetCommitsInfo/linux-4 20 813171326 ns/op ``` __IMPLEMENTATION DETAILS__: Gets the 16 latest commits affecting the relevant entries (`git log --name-only -16 HEAD -- <treePath>`). The output of this command containing which files were affect by each commit. Scan through this list of cmmit, and stop once a commit has been found for each entry. If you go through the first batch of 16 commits, you get then next 32 commits (`git log --name-only -32 <last-commit-from-first-batch>^ -- entry1 entry2 ...`); each time you double the number of commits. This ensures that in the common case you'll only have to read in a small number (16) of commits, but you also won't have to make too many calls to `git log` if you need to go further into the commit history. Finally, if you are looking for 32 or fewer entries, manually list out each entry in the `git log` command (`git log --name-only -- entry1 entry2...`) to support a more targeted search. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 10:23:59 -05:00
yindo closed this issue 2026-02-16 10:23:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: go-gitea/git#61