This patch introduces a branchmap.hasbranch() function to find whether a branch
exists or not. I was going through profile of one of most used command
internally on server side and found that we are spending ~50% of time finding
whether a branch exists or not. We are reading the branchmap cache, building the
related object and then finding whether a branch exists or not which is quite
slow on repositories which have more than 10k named branches.
In the new function, we just iterate over the whole branchmap cache and find
that whether a branch name is present or not. This is essentially
branchmap.read() but without any hash validation, creation of the branchcache()
object.
Following were the improvements observed:
Before:
hg log -b . -l 1: 0.53 sec
hg log -b <last_branch_in_the_cache> -l 1: 1.12 sec
After:
hg log -b . -l 1: 0.32 sec
hg log -b <last_branch_in_the_cache> -l 1: 0.95 sec
There we no improvements observed in hg log -r <branch_name>, if the log limit
is greater than 1, and while using revsets.
I have added a TODO here that we can use binary search instead of plain
iteration for finding whether a branch name exists or not. I got to know that
Martijn Pieters is working on some related stuff to load branchmap in memory as
raw data and decided to implement binary search on top of that.