git-gui: More performance improvements to rescan logic.
Removed as much as possible from the merge_state proc, which is where we spent most of our time before UI update. This change makes our running time match that of git status, except that we then need about 7 additional seconds to draw 6900 files on screen. Apparently the [array names a -exact $v] operator in Tcl is O(n) rather than O(1), which is really quite disappointing given that each array can only have one entry for a given value. Switching to a lookup with a catch (whose error we ignore) runs in O(1) time and bought us most of that improvement. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 7, 2006 at 19:58 UTC
6b29267542546b443fd885b2ed6dc896680b09ed
1 file changed
+43
-44
git-gui
+43
-44
@@ -70,7 +70,7 @@ proc repository_state {hdvar ctvar} {
70
proc update_status {{final Ready.}} {
71
global HEAD PARENT commit_type
72
global ui_index ui_other ui_status_value ui_comm
73
- global status_active file_states
73
+ global status_active file_states status_start
74
75
if {$status_active || ![lock_index read]} return
76
@@ -84,6 +84,7 @@ proc update_status {{final Ready.}} {
84
set commit_type $new_type
85
}
86
87
+ set status_start [clock seconds]
88
array unset file_states
89
foreach w [list $ui_index $ui_other] {
90
$w conf -state normal
@@ -230,7 +231,7 @@ proc read_ls_others {fd final} {
231
}
232
233
proc status_eof {fd buf final} {
233
- global status_active $buf
234
+ global status_active status_start $buf
235
global ui_fname_value ui_status_value file_states
236
237
if {[eof $fd]} {
@@ -240,8 +241,12 @@ proc status_eof {fd buf final} {
241
if {[incr status_active -1] == 0} {
242
unlock_index
243
243
- set ui_status_value $final
244
+ set e1 [clock seconds]
245
display_all_files
246
+ set e2 [clock seconds]
247
+puts "TIME [expr $e1 - $status_start] + [expr $e2 - $e1] = [expr $e2 - $status_start]"
248
+
249
+ set ui_status_value $final
250
251
if {$ui_fname_value != {} && [array names file_states \
252
-exact $ui_fname_value] != {}} {
@@ -664,11 +669,11 @@ proc push_to {remote} {
669
## ui helpers
670
671
proc mapcol {state path} {
667
- global all_cols
672
+ global all_cols ui_other
673
674
if {[catch {set r $all_cols($state)}]} {
675
puts "error: no column for state={$state} $path"
671
- return o
676
+ return $ui_other
677
}
678
return $r
679
}
@@ -716,31 +721,34 @@ proc bsearch {w path} {
721
722
set next_icon_id 0
723
719
-proc merge_state {path state} {
724
+proc merge_state {path new_state} {
725
global file_states next_icon_id
726
722
- if {[array names file_states -exact $path] == {}} {
723
- set m __
724
- set s [list $m icon[incr next_icon_id]]
727
+ set s0 [string index $new_state 0]
728
+ set s1 [string index $new_state 1]
729
+
730
+ if {[catch {set info $file_states($path)}]} {
731
+ set state __
732
+ set icon n[incr next_icon_id]
733
} else {
726
- set s $file_states($path)
727
- set m [lindex $s 0]
734
+ set state [lindex $info 0]
735
+ set icon [lindex $info 1]
736
}
737
730
- if {[string index $state 0] == {_}} {
731
- set state [string index $m 0][string index $state 1]
732
- } elseif {[string index $state 0] == {*}} {
733
- set state _[string index $state 1]
738
+ if {$s0 == {_}} {
739
+ set s0 [string index $state 0]
740
+ } elseif {$s0 == {*}} {
741
+ set s0 _
742
}
743
736
- if {[string index $state 1] == {_}} {
737
- set state [string index $state 0][string index $m 1]
738
- } elseif {[string index $state 1] == {*}} {
739
- set state [string index $state 0]_
744
+ if {$s1 == {_}} {
745
+ set s1 [string index $state 1]
746
+ } elseif {$s1 == {*}} {
747
+ set s1 _
748
}
749
742
- set file_states($path) [lreplace $s 0 0 $state]
743
- return $m
750
+ set file_states($path) [list $s0$s1 $icon]
751
+ return $state
752
}
753
754
proc display_file {path state} {
@@ -750,19 +758,12 @@ proc display_file {path state} {
758
if {$status_active} return
759
760
set s $file_states($path)
761
+ set old_w [mapcol $old_m $path]
762
+ set new_w [mapcol $new_m $path]
763
set new_m [lindex $s 0]
754
- set new_col [mapcol $new_m $path]
764
set new_ico [mapicon $new_m $path]
765
757
- if {$new_col == {o}} {
758
- set old_w $ui_index
759
- set new_w $ui_other
760
- } else {
761
- set old_w $ui_other
762
- set new_w $ui_index
763
- }
764
-
765
- if {$new_col != [mapcol $old_m $path]} {
766
+ if {$new_w != $old_w} {
767
set lno [bsearch $old_w $path]
768
if {$lno >= 0} {
769
incr lno
@@ -795,18 +796,12 @@ proc display_all_files {} {
796
foreach path [lsort [array names file_states]] {
797
set s $file_states($path)
798
set m [lindex $s 0]
798
-
799
- if {[mapcol $m $path] == {o}} {
800
- set aw $ui_other
801
- } else {
802
- set aw $ui_index
803
- }
804
-
805
- $aw image create end \
799
+ set w [mapcol $m $path]
800
+ $w image create end \
801
-align center -padx 5 -pady 1 \
802
-name [lindex $s 1] \
803
-image [mapicon $m $path]
809
- $aw insert end "$path\n"
804
+ $w insert end "$path\n"
805
}
806
807
$ui_index conf -state disabled
@@ -1025,6 +1020,8 @@ static unsigned char file_merge_bits[] = {
1020
0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1021
} -maskdata $filemask
1022
1023
+set ui_index .vpane.files.index.list
1024
+set ui_other .vpane.files.other.list
1025
set max_status_desc 0
1026
foreach i {
1027
{__ i plain "Unmodified"}
@@ -1035,7 +1032,7 @@ foreach i {
1032
{_O o plain "Untracked"}
1033
{A_ o fulltick "Added"}
1034
{AM o parttick "Partially added"}
1038
- {AD o question "Added (but now gone)"}
1035
+ {AD o question "Added (but now gone)"}
1036
1037
{_D i question "Missing"}
1038
{D_ i removed "Removed"}
@@ -1048,7 +1045,11 @@ foreach i {
1045
if {$max_status_desc < [string length [lindex $i 3]]} {
1046
set max_status_desc [string length [lindex $i 3]]
1047
}
1051
- set all_cols([lindex $i 0]) [lindex $i 1]
1048
+ if {[lindex $i 1] == {i}} {
1049
+ set all_cols([lindex $i 0]) $ui_index
1050
+ } else {
1051
+ set all_cols([lindex $i 0]) $ui_other
1052
+ }
1053
set all_icons([lindex $i 0]) file_[lindex $i 2]
1054
set all_descs([lindex $i 0]) [lindex $i 3]
1055
}
@@ -1461,7 +1462,6 @@ panedwindow .vpane.files -orient horizontal
1462
pack .vpane -anchor n -side top -fill both -expand 1
1463
1464
# -- Index File List
1464
-set ui_index .vpane.files.index.list
1465
frame .vpane.files.index -height 100 -width 400
1466
label .vpane.files.index.title -text {Modified Files} \
1467
-background green \
@@ -1479,7 +1479,6 @@ pack $ui_index -side left -fill both -expand 1
1479
.vpane.files add .vpane.files.index -sticky nsew
1480
1481
# -- Other (Add) File List
1482
-set ui_other .vpane.files.other.list
1482
frame .vpane.files.other -height 100 -width 100
1483
label .vpane.files.other.title -text {Untracked Files} \
1484
-background red \