hg pull very slow on a repository with a lot of tags and branches
Pulling from a repository that contains a lot of tags and branches (over 2000) is very slow even when there is nothing to do. E.g. the following output shows up quickly:
> hg pull
pulling from git+https://redacted
no changes found
Then I have to wait over 2 minutes for the command to complete and the shell prompt to return.
I was able to trace the issue to git_handler.py:1933 and git_handler.py:1937 which get called for each ref and trigger a call to fsync
inside dulwich.
I was able to fix the issue by checking if we're really trying to set a new hash or if we're just rewriting the same one:
@@ -1930,11 +1928,13 @@
remote_refs[remote_head] = bin(hgsha)
# TODO(durin42): what is this doing?
new_ref = REMOTE_BRANCH_PREFIX + remote_head
- self.git.refs[new_ref] = sha
+ if self.git.refs.follow (new_ref)[1] != sha:
+ self.git.refs[new_ref] = sha
elif ref_name.startswith(
LOCAL_TAG_PREFIX
) and not ref_name.endswith(ANNOTATED_TAG_SUFFIX):
- self.git.refs[ref_name] = sha
+ if self.git.refs.follow (ref_name)[1] != sha:
+ self.git.refs[ref_name] = sha
if hgsha:
all_remote_nodeids.append(bin(hgsha))