Skip to content

Commit 7c62337

Browse files
committed
Update commits every 0.1 sec instead of every 1000 commits
Slower machines will update more often and faster ones will do more work in each update.
1 parent 53d92fb commit 7c62337

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

PBGitHistoryGrapher.m

+10-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ - (void) graphCommits:(NSArray *)revList
3838
if (!revList || [revList count] == 0)
3939
return;
4040

41+
//NSDate *start = [NSDate date];
4142
NSThread *currentThread = [NSThread currentThread];
43+
NSDate *lastUpdate = [NSDate date];
4244
NSMutableArray *commits = [NSMutableArray array];
4345
NSInteger counter = 0;
4446

@@ -54,11 +56,16 @@ - (void) graphCommits:(NSArray *)revList
5456
[searchSHAs addObjectsFromArray:[commit parents]];
5557
}
5658
}
57-
if (++counter % 2000 == 0) {
58-
[self sendCommits:commits];
59-
commits = [NSMutableArray array];
59+
if (++counter % 100 == 0) {
60+
if ([[NSDate date] timeIntervalSinceDate:lastUpdate] > 0.1) {
61+
[self sendCommits:commits];
62+
commits = [NSMutableArray array];
63+
lastUpdate = [NSDate date];
64+
}
6065
}
6166
}
67+
//NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:start];
68+
//NSLog(@"Graphed %i commits in %f seconds (%f/sec)", counter, duration, counter/duration);
6269

6370
[self sendCommits:commits];
6471
[delegate performSelectorOnMainThread:@selector(finishedGraphing) withObject:nil waitUntilDone:NO];

PBGitRevList.mm

+12-7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ - (void) updateCommits:(NSDictionary *)update
9696
- (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
9797
{
9898
NSDate *start = [NSDate date];
99+
NSDate *lastUpdate = [NSDate date];
99100
NSMutableArray *revisions = [NSMutableArray array];
100101
PBGitGrapher *g = [[PBGitGrapher alloc] initWithRepository:repository];
101102
std::map<string, NSStringEncoding> encodingMap;
@@ -125,6 +126,9 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
125126

126127
int num = 0;
127128
while (true) {
129+
if ([currentThread isCancelled])
130+
break;
131+
128132
string sha;
129133
if (!getline(stream, sha, '\1'))
130134
break;
@@ -200,18 +204,19 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
200204
if (isGraphing)
201205
[g decorateCommit:newCommit];
202206

203-
if (++num % 1000 == 0) {
204-
if ([currentThread isCancelled])
205-
break;
206-
NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys:currentThread, kRevListThreadKey, revisions, kRevListRevisionsKey, nil];
207-
[self performSelectorOnMainThread:@selector(updateCommits:) withObject:update waitUntilDone:NO];
208-
revisions = [NSMutableArray array];
207+
if (++num % 100 == 0) {
208+
if ([[NSDate date] timeIntervalSinceDate:lastUpdate] > 0.1) {
209+
NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys:currentThread, kRevListThreadKey, revisions, kRevListRevisionsKey, nil];
210+
[self performSelectorOnMainThread:@selector(updateCommits:) withObject:update waitUntilDone:NO];
211+
revisions = [NSMutableArray array];
212+
lastUpdate = [NSDate date];
213+
}
209214
}
210215
}
211216

212217
if (![currentThread isCancelled]) {
213218
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:start];
214-
NSLog(@"Loaded %i commits in %f seconds", num, duration);
219+
NSLog(@"Loaded %i commits in %f seconds (%f/sec)", num, duration, num/duration);
215220

216221
// Make sure the commits are stored before exiting.
217222
NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys:currentThread, kRevListThreadKey, revisions, kRevListRevisionsKey, nil];

0 commit comments

Comments
 (0)