Tk Source Code

View Ticket
Login
Ticket UUID: 7d8d10e4a97ad928d7d2e72fa61a8981c771160c
Title: Tk console extremely slow before first display
Type: Bug Version: 8.6.17
Submitter: anonymous Created on: 2025-09-19 06:21:47
Subsystem: 18. [text] Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Severe
Status: Closed Last Modified: 2026-10-08 15:54:02
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2026-10-08 15:54:02
Description:
We have observed the following behaviour:

* Wish (and DVRun) automatically create a Tk Console
* The console is created as well when a startup script is specified (consoleRequired is still TRUE).  In this case the console is not displayed.
* If the script outputs before the console is displayed, output is extremely slow (1000 lines ~ 6 seconds)
* If the console is displayed (`::console show`), output becomes considerably faster (1000 lines ~ 1 second)
* If the console is then hidden (`::console hide`), output stays considerably fast (1000 lines ~ 1 second)
* If the console is destroyed (`rename ::console ""`), output is immediate (1000 lines ~ 0 seconds)

Note that this issue affects only Windows, as under Linux the Tk Console is not used.

The following script demonstrates the issue:

```
toplevel .t
button .t.b -text "Puts..." -command {time {puts HELLO} 500}
button .t.e -text "Exit..." -command {exit 0}
button .t.cs -text "Show..." -command {console show}
button .t.ch -text "Hide..." -command {console hide}
pack .t.b .t.e .t.cs .t.ch
```

Run with `wish slowconsole.tcl`.

This issue causes any script that outputs (for example debugging output) extremely slow.
User Comments: jan.nijtmans added on 2026-10-08 15:54:02:

I see that @nab already fixed the textDisp-39.1 testcase in [8c1e9d5fd4094ba2|this] commit.

Many thanks!


jan.nijtmans added on 2026-10-08 14:30:57:

This 'fix' has a side-effect:

==== textDisp-39.1 no line break inside a grapheme cluster ending the text, line one pixel wide FAILED
==== Contents of test case:
    # Laid out before the first display: a single grapheme cluster is forced on each line.
    foreach mode {char word} {
	destroy .t1
	text .t1 -font {Courier -12} -width 17 -wrap $mode
	pack .t1
	.t1 insert end $graphemeText
	.t1 count -update -displaylines 1.0 end
    update
	lappend res $mode [displayLineCodePoints .t1]
    }
    set res
---- Result was:
char U+0065.U+0301.U+0065.U+0301.U+1F469.U+200D.U+1F4BB word U+0065.U+0301.U+0065.U+0301.U+1F469.U+200D.U+1F4BB
---- Result should have been (exact matching):
char {U+0065.U+0301 U+0065.U+0301 U+1F469.U+200D.U+1F4BB} word {U+0065.U+0301 U+0065.U+0301 U+1F469.U+200D.U+1F4BB}
==== textDisp-39.1 FAILED

Wondering what to do


jan.nijtmans added on 2026-10-08 12:44:57:

Fixed in [a5863c1d2aa53281|trunk], backported to core-9-0-branch

(not yet backported to 8.6)


serhiy.storchaka added on 2026-09-18 19:52:49:

Reproduced on Windows 11 with 8.6.18 and 9.1. The text widget of the hidden console has size 1x1, so with -wrap char every character is a display line, and every see (explicit or implicit when inserting on the top line) lays out dozens of display lines, each with a font measurement. Not specific to the console, it affects any text widget in an unmapped toplevel.

Fix in branch [fc8c4f12ef]: lay out the text with the requested size while the window is 1x1.