Skip to content

Loading…

Performance Improvement #28

Merged
merged 2 commits into from

2 participants

@nufyoot

Hey Phil Haack! I love this project and have found it to be a great tool for visualizing our local Git repos. I noticed that strarting up the application would take a while, especially if there were a few merged branches. I added this section of code and compared the results of our local repos along with your SeeGit repo and the visual graph matches. For your SeeGit repo, AddCommitsToGraph was cut down from 94,199 calls to 108.

Let me know what you think!

@Haacked Haacked commented on an outdated diff
SeeGitApp/Models/RepositoryGraphBuilder.cs
@@ -93,6 +93,10 @@ private void AddCommitsToGraph(Commit commit, CommitVertex childVertex)
_graph.AddEdge(edge);
_edges.Add(edge.Id, edge);
}
+ else
+ {
@Haacked Owner
Haacked added a note

If we add an else case here, we should invert the if statement. I find:

if (!something)
{
}
else
{
}

Harder to read and grok than:

if (something)
{}
else
{}

Also, at first glance, I'm not sure how this works properly. Is it because if the edge exists, we must have already added this commit and its parents?

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

That's a good point. In that case, would you keep the else since the if would just return? Example:

if (_edges.ContainsKey(edge.Id))
{
    return;
}
_graph.AddEdge(edge);
_edges.Add(edge.Id, edge);

As for the reason. For each branch in the graph it will ask to add an edge from commit A to commit B and from commit A to commit C (given that A was a merge of B and C). When the ancestors of B and C come back to D (given that D is a common ancestor of B and C) then both B and C have started a graph walk and will walk the graph twice. The larger the repository, the worse this would become.

So, using A, B, C and D from above, and introducing E (where E is an ancestor of D) then this code states "If you've already added an edge from D to E (perhaps A -> B -> D -> E) then we don't need to walk the graph past E (perhaps A -> C -> D -> E)."

I hope I have this correct. Also, I would love to contribute more to this project if it's alright with you!

@Haacked
Owner

It is definitely cool with me if you want to contribute more. :) I'm going to be spending more time on this soon and would love the help.

@Haacked Haacked merged commit f921d40 into Haacked:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 11, 2012
  1. @nufyoot

    If an edge already exists, don't run through the commit graph again. …

    nufyoot committed
    …This should speed up the loading of the graph.
Commits on May 14, 2012
  1. @nufyoot
Showing with 4 additions and 6 deletions.
  1. +4 −6 SeeGitApp/Models/RepositoryGraphBuilder.cs
View
10 SeeGitApp/Models/RepositoryGraphBuilder.cs
@@ -88,11 +88,9 @@ private void AddCommitsToGraph(Commit commit, CommitVertex childVertex)
if (childVertex != null)
{
var edge = new CommitEdge(childVertex, commitVertex);
- if (!_edges.ContainsKey(edge.Id))
- {
- _graph.AddEdge(edge);
- _edges.Add(edge.Id, edge);
- }
+ if (_edges.ContainsKey(edge.Id)) return;
+ _graph.AddEdge(edge);
+ _edges.Add(edge.Id, edge);
}
foreach (var parent in commit.Parents)
@@ -106,7 +104,7 @@ private CommitVertex GetCommitVertex(Commit commit)
CommitVertex commitVertex;
if (!_vertices.TryGetValue(commit.Sha, out commitVertex))
{
- commitVertex = new CommitVertex(commit.Sha, commit.MessageShort) {Description = commit.Message};
+ commitVertex = new CommitVertex(commit.Sha, commit.MessageShort) { Description = commit.Message };
_vertices.Add(commit.Sha, commitVertex);
}
Something went wrong with that request. Please try again.