@matheusbsbs / matheus-bagliano / commits / d1e46756d3
Fork 0

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 <paulus@samba.org>

Paul Mackerras committed Aug 16, 2006 at 20:02 UTC d1e46756d312f65613863a41c256d852fcde330c
1 file changed +34 -24
gitk
+34 -24
@@ -17,13 +17,12 @@ proc gitdir {} {
17 }
18
19 proc start_rev_list {view} {
20 - global startmsecs nextupdate ncmupdate
20 + global startmsecs nextupdate
21 global commfd leftover tclencoding datemode
22 global viewargs viewfiles commitidx
23
24 set startmsecs [clock clicks -milliseconds]
25 set nextupdate [expr {$startmsecs + 100}]
26 - set ncmupdate 1
26 set commitidx($view) 0
27 set args $viewargs($view)
28 if {$viewfiles($view) ne {}} {
@@ -79,7 +78,7 @@ proc getcommitlines {fd view} {
78 global parentlist childlist children curview hlview
79 global vparentlist vchildlist vdisporder vcmitlisted
80
82 - set stuff [read $fd]
81 + set stuff [read $fd 500000]
82 if {$stuff == {}} {
83 if {![eof $fd]} return
84 global viewname
@@ -185,7 +184,7 @@ proc getcommitlines {fd view} {
184 }
185 if {$gotsome} {
186 if {$view == $curview} {
188 - layoutmore
187 + while {[layoutmore $nextupdate]} doupdate
188 } elseif {[info exists hlview] && $view == $hlview} {
189 vhighlightmore
190 }
@@ -196,20 +195,13 @@ proc getcommitlines {fd view} {
195 }
196
197 proc doupdate {} {
199 - global commfd nextupdate numcommits ncmupdate
198 + global commfd nextupdate numcommits
199
200 foreach v [array names commfd] {
201 fileevent $commfd($v) readable {}
202 }
203 update
204 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 - }
205 foreach v [array names commfd] {
206 set fd $commfd($v)
207 fileevent $fd readable [list getcommitlines $fd $v]
@@ -1697,7 +1689,7 @@ proc showview {n} {
1689 show_status "Reading commits..."
1690 }
1691 if {[info exists commfd($n)]} {
1700 - layoutmore
1692 + layoutmore {}
1693 } else {
1694 finishcommits
1695 }
@@ -2378,20 +2370,38 @@ proc visiblerows {} {
2370 return [list $r0 $r1]
2371 }
2372
2381 -proc layoutmore {} {
2373 +proc layoutmore {tmax} {
2374 global rowlaidout rowoptim commitidx numcommits optim_delay
2375 global uparrowlen curview
2376
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 + }
2405 }
2406 }
2407