So the Object construction in the branches/tags context is actually just a ming
Object (aka a dict with object-like attr access). And the
['**is_valid**'](https://github.com/gitpython-developers/GitPython/blob/master/git/refs/symbolic.py#L330)
is just doing a simple try/except itself -- so I don't think expanding the
list comprehension for our own try/except be any cheaper **unless**...
We use git fsck as the try/except and only check **is_valid** for the very rare
cases that it finds an issue. I attached a profile of running
**`self._git.git.fsck(full=True)`** and it's very cheap even with 1000s of
branches.
~~~~~
@LazyProperty
def branches(self):
try:
self._git.git.fsck(full=True)
except git.GitCommandError as gce:
log.debug(u"Found inconsistency in {}: {}".format(self._repo.name,
gce.stderr))
return [Object(name=b.name, object_id=b.commit.hexsha) for b in
self._git.branches if b.is_valid()]
return [Object(name=b.name, object_id=b.commit.hexsha) for b in
self._git.branches]
~~~~~
This looks like it's a pretty good trade-off between handling invalid refs and
performance. It would have the added benefit of informing us of issues instead
of just silently returning valid results.
I pushed an optimized version of this idea if you want to take a look.
**hs/7873**
Attachment: Screen Shot 2015-06-10 at 9.56.42 AM.png (552.9 kB; image/png)
---
** [tickets:#7873] Git branch & tag speedups**
**Status:** in-progress
**Milestone:** unreleased
**Labels:** performance sf-current sf-4
**Created:** Fri Apr 17, 2015 09:23 PM UTC by Dave Brondsema
**Last Updated:** Tue Jun 09, 2015 09:57 PM UTC
**Owner:** Heith Seewald
I saw that git pages on forge-allura.apache.org were slow, so I looked at
stats.log and saw that the sidebar was the slowest part. I did some additional
digging and found 2 specific areas for improvement:
* in `git_main.py` change `default_branch_name` to a `@LazyProperty` since it
is called many times inside a loop in `RepositoryApp.sidebar_menu`
* Since `sidebar_menu` only requests a certain number of branches, pass that
"limit" all the way through to `git_repo.py`'s `branches` method so that
`is_valid()` is only called a minimum number of times needed.
* make sure the default branch logic to put it at the top of the list still
works (e.g. always put it at the top first)
In addition to those changes, generalize and apply the same approach to the
tags. And also check ForgeHg to see if mercurial can benefit the same way.
---
Sent from forge-allura.apache.org because [email protected] is subscribed
to https://forge-allura.apache.org/p/allura/tickets/
To unsubscribe from further messages, a project admin can change settings at
https://forge-allura.apache.org/p/allura/admin/tickets/options. Or, if this is
a mailing list, you can unsubscribe from the mailing list.