Skip to content

Commit d1e4675

Browse files
committed
gitk: Improve responsiveness while reading and layout out the graph
This restructures layoutmore so that it can take a time limit and do limited amounts of graph layout and graph optimization, and return 1 if it exceeded the time limit before finishing everything it could do. Also getcommitlines reads at most half a megabyte each time, to limit the time it spends parsing the commits to about a tenth of a second. Also got rid of the unused ncmupdate variable while I was at it. Signed-off-by: Paul Mackerras <[email protected]>
1 parent ceadfe9 commit d1e4675

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

gitk

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ proc gitdir {} {
1717
}
1818

1919
proc start_rev_list {view} {
20-
global startmsecs nextupdate ncmupdate
20+
global startmsecs nextupdate
2121
global commfd leftover tclencoding datemode
2222
global viewargs viewfiles commitidx
2323

2424
set startmsecs [clock clicks -milliseconds]
2525
set nextupdate [expr {$startmsecs + 100}]
26-
set ncmupdate 1
2726
set commitidx($view) 0
2827
set args $viewargs($view)
2928
if {$viewfiles($view) ne {}} {
@@ -79,7 +78,7 @@ proc getcommitlines {fd view} {
7978
global parentlist childlist children curview hlview
8079
global vparentlist vchildlist vdisporder vcmitlisted
8180

82-
set stuff [read $fd]
81+
set stuff [read $fd 500000]
8382
if {$stuff == {}} {
8483
if {![eof $fd]} return
8584
global viewname
@@ -185,7 +184,7 @@ proc getcommitlines {fd view} {
185184
}
186185
if {$gotsome} {
187186
if {$view == $curview} {
188-
layoutmore
187+
while {[layoutmore $nextupdate]} doupdate
189188
} elseif {[info exists hlview] && $view == $hlview} {
190189
vhighlightmore
191190
}
@@ -196,20 +195,13 @@ proc getcommitlines {fd view} {
196195
}
197196

198197
proc doupdate {} {
199-
global commfd nextupdate numcommits ncmupdate
198+
global commfd nextupdate numcommits
200199

201200
foreach v [array names commfd] {
202201
fileevent $commfd($v) readable {}
203202
}
204203
update
205204
set nextupdate [expr {[clock clicks -milliseconds] + 100}]
206-
if {$numcommits < 100} {
207-
set ncmupdate [expr {$numcommits + 1}]
208-
} elseif {$numcommits < 10000} {
209-
set ncmupdate [expr {$numcommits + 10}]
210-
} else {
211-
set ncmupdate [expr {$numcommits + 100}]
212-
}
213205
foreach v [array names commfd] {
214206
set fd $commfd($v)
215207
fileevent $fd readable [list getcommitlines $fd $v]
@@ -1697,7 +1689,7 @@ proc showview {n} {
16971689
show_status "Reading commits..."
16981690
}
16991691
if {[info exists commfd($n)]} {
1700-
layoutmore
1692+
layoutmore {}
17011693
} else {
17021694
finishcommits
17031695
}
@@ -2378,20 +2370,38 @@ proc visiblerows {} {
23782370
return [list $r0 $r1]
23792371
}
23802372

2381-
proc layoutmore {} {
2373+
proc layoutmore {tmax} {
23822374
global rowlaidout rowoptim commitidx numcommits optim_delay
23832375
global uparrowlen curview
23842376

2385-
set row $rowlaidout
2386-
set rowlaidout [layoutrows $row $commitidx($curview) 0]
2387-
set orow [expr {$rowlaidout - $uparrowlen - 1}]
2388-
if {$orow > $rowoptim} {
2389-
optimize_rows $rowoptim 0 $orow
2390-
set rowoptim $orow
2391-
}
2392-
set canshow [expr {$rowoptim - $optim_delay}]
2393-
if {$canshow > $numcommits} {
2394-
showstuff $canshow
2377+
while {1} {
2378+
if {$rowoptim - $optim_delay > $numcommits} {
2379+
showstuff [expr {$rowoptim - $optim_delay}]
2380+
} elseif {$rowlaidout - $uparrowlen - 1 > $rowoptim} {
2381+
set nr [expr {$rowlaidout - $uparrowlen - 1 - $rowoptim}]
2382+
if {$nr > 100} {
2383+
set nr 100
2384+
}
2385+
optimize_rows $rowoptim 0 [expr {$rowoptim + $nr}]
2386+
incr rowoptim $nr
2387+
} elseif {$commitidx($curview) > $rowlaidout} {
2388+
set nr [expr {$commitidx($curview) - $rowlaidout}]
2389+
# may need to increase this threshold if uparrowlen or
2390+
# mingaplen are increased...
2391+
if {$nr > 150} {
2392+
set nr 150
2393+
}
2394+
set row $rowlaidout
2395+
set rowlaidout [layoutrows $row [expr {$row + $nr}] 0]
2396+
if {$rowlaidout == $row} {
2397+
return 0
2398+
}
2399+
} else {
2400+
return 0
2401+
}
2402+
if {$tmax ne {} && [clock clicks -milliseconds] >= $tmax} {
2403+
return 1
2404+
}
23952405
}
23962406
}
23972407

0 commit comments

Comments
 (0)