| Ticket UUID: | 80213d1b1c8458e1655b608d73b637d7d273879 | |||
| Title: | text widget's see subcommand can take many seconds | |||
| Type: | Bug | Version: | 8.6.*, 8.7a*, trunk | |
| Submitter: | nemethi | Created on: | 2021-08-03 17:49:38 | |
| Subsystem: | 18. [text] | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Severe | |
| Status: | Closed | Last Modified: | 2026-10-06 13:53:13 | |
| Resolution: | Fixed | Closed By: | nemethi | |
| Closed on: | 2026-10-06 13:53:13 | |||
| Description: |
In the presence of a large number of elided lines, the text widget's see subcommand can take many seconds, as demonstrated by the following script:
text .t -yscrollcommand [list .vsb set]
for {set n 1} {$n <= 10000} {incr n} {
.t insert end "Line $n\n"
}
.t tag configure Elided -elide 1
.t tag add Elided 6.0 9951.0
scrollbar .vsb -orient vertical -command [list .t yview]
pack .vsb -side right -fill y
pack .t -side right -expand 1 -fill both
# Patch the Tk library procedure ::tk::TextSetCursor (see file text.tcl)
# by adding code that measures the time consumed by "$w see insert".
# This proc is invoked, e.g., from within the binding for <<NextLine>>.
proc ::tk::TextSetCursor {w pos} {
if {[$w compare $pos == end]} {
set pos {end - 1 chars}
}
$w mark set insert $pos
$w tag remove sel 1.0 end
puts "invoking \"$w see insert\" ..."
set startTime [clock seconds]
$w see insert
set stopTime [clock seconds]
puts "done -- it took [expr {$stopTime - $startTime}] seconds"
if {[$w cget -autoseparators]} {
$w edit separator
}
}
Start the script, click anywhere into the window's bottom line (Line 9969), and then press the Down key. The output produced by the script on my Linux box will look like
invoking ".t see insert" ...
done -- it took 25 seconds
As seen from this output, in this case the text widget's see subcommand takes an unacceptably long time. On a faster computer you will see maybe 20 or "only" 15 seconds, but all these times are by far beyond the values that can be viewed as user-friendly.
For comparison: With Tk 8.5 or a Tk version built from the revised_text branch, the see subcommand takes at most a few milliseconds. Unfortunately, revised_text still suffers from several other problems. For example, if you click anywhere into Line 9951 then the Down key will jump to the end of the text, because the ::tk::TextUpDownLine proc returns an incorrect index. In addition, Tk built from this branch quite often produces a segmentation fault (this might be the subject of a separate ticket).
| |||
| User Comments: |
nemethi (claiming to be Csaba Nemethi) added on 2026-10-06 13:53:13:
Serhiy, many thanks for the brilliant fix and its improvement that avoids the panic in debug mode! Merged into main (by commits [214a5f51], [01c63d0a]), core-9-0-branch (by commits [01174ca8], [ff77f31e]), and core-8-6-branch (by commits [46a94e56], [19a6d09b]). serhiy.storchaka added on 2026-10-06 10:59:51: The fix [24ac48f567] makes textDisp-11.19 panic in debug mode with "CalculateDisplayLineHeight called with bad indexPtr": in 4 of 5 Linux test jobs on CI today, but only in about 10% of textDisp.test runs on my machine (9 of 80), this is why it was not caught. TkTextUpdateOneLine now passes the start of an entirely elided line which is merged with the previous line, and the debug check rejected it. The heights are computed correctly, only the check was too strict. Proposed fix in branch [c026c66c37], with test textDisp-19.20, which reproduces the panic every time. serhiy.storchaka added on 2026-09-18 20:50:36: Same cause as [4c595d4d78], reached through nemethi (claiming to be Csaba Nemethi) added on 2022-09-05 16:34:39: That problem was the subject of ticket [934cab5005]. fvogel added on 2022-09-04 19:51:39: The problem with the revised text widget mentioned at the end of this report regarding ::tk::TextUpDownLine must have been solved, I cannot reproduce it anymore. | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki