Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

More efficient counting of tags/remotes/heads #121

wants to merge 8 commits into


None yet
3 participants

In Gitlab the number of tags is shown, using the command repo.tags.count. Now we have some very large repositories where this takes a lot of time, and slows down the complete UI.

Instead of first building the list of tags, just to take the size of it, I added a method count_all to Ref, which can then be used to implement the methods tag_count, head_count and remote_count on Repo.

Some timings, to start on the grit repository itself:

ruby-1.9.3-p125@grit ~/work/git/grit (master) $ irb
1.9.3p125 :001 > require 'grit'
 => true 
1.9.3p125 :002 > repo = Grit::Repo.new('.')
 => #<Grit::Repo "/home/nathan/work/git/grit/.git"> 
1.9.3p125 :003 > repo.tag_count
 => 15 
1.9.3p125 :004 > repo.tags.count
 => 15 
1.9.3p125 :005 > require 'benchmark'
 => true 
1.9.3p125 :006 > Benchmark.measure { repo.tag_count }
 =>   0.000000   0.000000   0.000000 (  0.000788)

1.9.3p125 :007 > Benchmark.measure { repo.tags.count }
 =>   0.030000   0.000000   0.030000 (  0.024960)

Then, for good measurement, on our huge repository:

ruby-1.9.3-p125@grit ~/work/git/grit (master) $ irb 
1.9.3p125 :001 > require 'grit'
 => true 
1.9.3p125 :002 > require 'benchmark'
 => true 
1.9.3p125 :004 > repo = Grit::Repo.new('../../vasco/git/ttt')
 => #<Grit::Repo "/home/nathan/work/vasco/git/ttt/.git"> 
1.9.3p125 :005 > Benchmark.measure { repo.tag_count }
 =>   0.020000   0.000000   0.020000 (  0.023077)

1.9.3p125 :006 > Benchmark.measure { repo.tags.count }
 =>   4.130000   0.140000   4.270000 (  4.283126)

I added tests as well. Any remarks or suggestions?

dzaporozhets and others added some commits May 21, 2012

@dzaporozhets dzaporozhets GITLAB patch: More stable raw commit parsing 810e3c1
@nathanvda nathanvda Added a method count_all for faster counting. Added methods called ta…
…g_count, head_count and remote_count. These just count how many there are, without building the actual items. On big git repositories this makes a lot of difference.
@nathanvda nathanvda Alias head_count to branch_count. cbe9a70
@dzaporozhets dzaporozhets Merge pull request #1 from nathanvda/master
More efficient counting of tags/remotes/heads
@dzaporozhets dzaporozhets travis file added 1c56688
@dzaporozhets dzaporozhets Gemfile added 205c7da
@nathanvda nathanvda Make sure that Ref does not create the commit when doing a `find_all`…
…, but instead only looks for the commit when it is needed. Improves lookup time enormously.
@nathanvda nathanvda Fix build on ci. b3b214e

bkeepers commented Feb 3, 2014

Grit is no longer maintained. See #183 and check out libgit2/rugged.

@bkeepers bkeepers closed this Feb 3, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment