git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Restraining git pull/fetch to the current branch

From
Julian Phillips <julian@quantumfyre.co.uk>
Date
Jan 15, 2007, 13:06 UTC
Message-ID
<Pine.LNX.4.64.0701151253190.9916@reaper.quantumfyre.co.uk>
In-Reply-To
<Pine.LNX.4.64.0701121332100.1493@reaper.quantumfyre.co.uk>
On Fri, 12 Jan 2007, Julian Phillips wrote:
Show 12 quoted lines
>>  I suspect most of the time is being spent in the
>>  append-fetch-head loop in fetch_main shell function in
>>  git-fetch.sh The true fix would not be to limit the number of
>>  branches updated, but to speed that part of the code up.
>
> Indeed, each call to append_fetch_head is taking ~1.7s (~1.5s user, ~0.2s 
> sys).  So simply looping over all the branches explains the ~27m that a 
> complete fetch takes. (This is for fetch with no updates).  Given that a 
> "clone orig new" takes ~8m30 (half of which would seem to be IO), it looks 
> like it may be faster to create a new repository each time instead of 
> updating the old one, which is certainly a viable workaround - but might 
> imply that fetch has some room for improvement?

I have had a chance to spend a little more time looking at this. It would appear that the major culprit is show-ref.

Running "git show-ref --hash <ref>" takes ~1.7s, compared to 0.002s for "cat $GIT_DIR/<ref>". If I add the following to the top of append_fetch_head a null fetch takes 1m28s instead of ~27m.

local_head_=$(cat $GIT_DIR/$local_name_);
if [ "$head_" == "$local_head_" ]; then
 	return;
fi

Looking at the code for show-ref it appears to looks at all the refs to find the one you ask for. This makes fetch O(n^2) in no of branches, which would seem not strictly necessary - but then I am not really familiar with the internal working of git. I noticed that the man page for show-ref says that its use over direct access is encouraged, but as it stands it is far too slow to be used in fetch when you have a large many-branched repository...

(In looking at this I also discovered that if you have too many branches then fetch will die with a too long command line error when calling git-fetch-pack.)

-- 
Julian

  ---
I will never lie to you.
Previous: Julian Phillips
Message 5 of 5 in “Restraining git pull/fetch to the current branch”
  1. Julian PhillipsJan 11, 2007
  2. Shawn O. PearceJan 12, 2007
  3. Junio C HamanoJan 12, 2007
  4. Julian PhillipsJan 12, 2007
  5. Julian PhillipsJan 15, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.