git-gui: Performance improvements for large file sets.
Loading 6900 newly added files required about 90 seconds on one system. This is just far too long to perform a "status" type of operation. git-status on the same system completes in just 8.2 seconds if it is redirected to /dev/null. Most of our performance improvement comes from moving all of the UI updating out of the main fileevent handlers for the status process. Instead we are only updating the file_states array and then only doing the UI update when all states are known and have been finally determined. The rescan execution is now down to almost 30 seconds for the same case, a good (but not really all that impressive) improvement. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 7, 2006 at 19:30 UTC
93f654df7ec9a509e9362e06821c2af0b2bacc82
1 file changed
+67
-40
git-gui
+67
-40
@@ -236,10 +236,13 @@ proc status_eof {fd buf final} {
236
if {[eof $fd]} {
237
set $buf {}
238
close $fd
239
+
240
if {[incr status_active -1] == 0} {
241
unlock_index
242
243
set ui_status_value $final
244
+ display_all_files
245
+
246
if {$ui_fname_value != {} && [array names file_states \
247
-exact $ui_fname_value] != {}} {
248
show_diff $ui_fname_value
@@ -711,79 +714,103 @@ proc bsearch {w path} {
714
return -[expr $lo + 1]
715
}
716
717
+set next_icon_id 0
718
+
719
proc merge_state {path state} {
715
- global file_states
720
+ global file_states next_icon_id
721
722
if {[array names file_states -exact $path] == {}} {
718
- set o __
719
- set s [list $o none none]
723
+ set m __
724
+ set s [list $m icon[incr next_icon_id]]
725
} else {
726
set s $file_states($path)
722
- set o [lindex $s 0]
727
+ set m [lindex $s 0]
728
}
729
725
- set m [lindex $s 0]
726
- if {[string index $state 0] == "_"} {
730
+ if {[string index $state 0] == {_}} {
731
set state [string index $m 0][string index $state 1]
728
- } elseif {[string index $state 0] == "*"} {
732
+ } elseif {[string index $state 0] == {*}} {
733
set state _[string index $state 1]
734
}
735
732
- if {[string index $state 1] == "_"} {
736
+ if {[string index $state 1] == {_}} {
737
set state [string index $state 0][string index $m 1]
734
- } elseif {[string index $state 1] == "*"} {
738
+ } elseif {[string index $state 1] == {*}} {
739
set state [string index $state 0]_
740
}
741
742
set file_states($path) [lreplace $s 0 0 $state]
739
- return $o
743
+ return $m
744
}
745
746
proc display_file {path state} {
743
- global ui_index ui_other file_states
747
+ global ui_index ui_other file_states status_active
748
749
set old_m [merge_state $path $state]
750
+ if {$status_active} return
751
+
752
set s $file_states($path)
747
- set m [lindex $s 0]
753
+ set new_m [lindex $s 0]
754
+ set new_col [mapcol $new_m $path]
755
+ set new_ico [mapicon $new_m $path]
756
749
- if {[mapcol $m $path] == "o"} {
750
- set ii 1
751
- set ai 2
752
- set iw $ui_index
753
- set aw $ui_other
757
+ if {$new_col == {o}} {
758
+ set old_w $ui_index
759
+ set new_w $ui_other
760
} else {
755
- set ii 2
756
- set ai 1
757
- set iw $ui_other
758
- set aw $ui_index
761
+ set old_w $ui_other
762
+ set new_w $ui_index
763
}
764
761
- set d [lindex $s $ii]
762
- if {$d != "none"} {
763
- set lno [bsearch $iw $path]
765
+ if {$new_col != [mapcol $old_m $path]} {
766
+ set lno [bsearch $old_w $path]
767
if {$lno >= 0} {
768
incr lno
766
- $iw conf -state normal
767
- $iw delete $lno.0 [expr $lno + 1].0
768
- $iw conf -state disabled
769
- set s [lreplace $s $ii $ii none]
769
+ $old_w conf -state normal
770
+ $old_w delete $lno.0 [expr $lno + 1].0
771
+ $old_w conf -state disabled
772
}
773
+
774
+ set lno [expr abs([bsearch $new_w $path] + 1) + 1]
775
+ $new_w conf -state normal
776
+ $new_w image create $lno.0 \
777
+ -align center -padx 5 -pady 1 \
778
+ -name [lindex $s 1] \
779
+ -image [mapicon $m $path]
780
+ $new_w insert $lno.1 "$path\n"
781
+ $new_w conf -state disabled
782
+ } elseif {$new_icon != [mapicon $old_m $path]} {
783
+ $new_w conf -state normal
784
+ $new_w image conf [lindex $s 1] -image $new_icon
785
+ $new_w conf -state disabled
786
}
787
+}
788
773
- set d [lindex $s $ai]
774
- if {$d == "none"} {
775
- set lno [expr abs([bsearch $aw $path] + 1) + 1]
776
- $aw conf -state normal
777
- set ico [$aw image create $lno.0 \
789
+proc display_all_files {} {
790
+ global ui_index ui_other file_states
791
+
792
+ $ui_index conf -state normal
793
+ $ui_other conf -state normal
794
+
795
+ foreach path [lsort [array names file_states]] {
796
+ set s $file_states($path)
797
+ 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 \
806
-align center -padx 5 -pady 1 \
779
- -image [mapicon $m $path]]
780
- $aw insert $lno.1 "$path\n"
781
- $aw conf -state disabled
782
- set file_states($path) [lreplace $s $ai $ai [list $ico]]
783
- } elseif {[mapicon $m $path] != [mapicon $old_m $path]} {
784
- set ico [lindex $d 0]
785
- $aw image conf $ico -image [mapicon $m $path]
807
+ -name [lindex $s 1] \
808
+ -image [mapicon $m $path]
809
+ $aw insert end "$path\n"
810
}
811
+
812
+ $ui_index conf -state disabled
813
+ $ui_other conf -state disabled
814
}
815
816
proc with_update_index {body} {