| Ticket UUID: | 4c595d4d788ea5142731ae3a3395151c32a724d1 | |||
| Title: | high cpu usage (100%) in tkTextDisp.c | |||
| Type: | Bug | Version: | 8.6.4 | |
| Submitter: | valdis | Created on: | 2015-10-28 06:46:03 | |
| Subsystem: | 18. [text] | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Severe | |
| Status: | Closed | Last Modified: | 2026-10-06 14:22:27 | |
| Resolution: | Fixed | Closed By: | nemethi | |
| Closed on: | 2026-10-06 14:22:27 | |||
| Description: |
Dell Latitude laptop, running Fedora Rawhide. Running exmh with Tk/cl 8.6.3 works fine. After upgrading to 8.6.4, I'm seeing 100% CPU usage by the wish binary. Oddly enough, exmh still operates normally, just sucking CPU in the background. Sometimes it will go CPU bound at startup, other times it won't start doing it for a while - but I've been unable to figure out what conditions trigger it. Equally mystifying - it can burn 30 minutes of CPU - and then stop and drop back to the 3-4% that exmh usually chews (this effect seems to happen mostly when I'm not even on the same virtual window as exmh, so it's not doing anything). Attaching to wish with gdb and playing the control-C/where game several times shows it's looping around in this code: (gdb) where #0 0x00007fe160fb4d8b in MeasureChars.isra.4 () from /lib64/libtk8.6.so #1 0x00007fe160fbca97 in TkTextCharLayoutProc () from /lib64/libtk8.6.so #2 0x00007fe160fb6b96 in LayoutDLine () from /lib64/libtk8.6.so #3 0x00007fe160fb9cfc in TkTextFindDisplayLineEnd () from /lib64/libtk8.6.so #4 0x00007fe160fba540 in TkTextUpdateOneLine () from /lib64/libtk8.6.so #5 0x00007fe160fba972 in TkTextUpdateLineMetrics () from /lib64/libtk8.6.so #6 0x00007fe160fbac06 in AsyncUpdateLineMetrics () from /lib64/libtk8.6.so #7 0x00007fe160c62d55 in ?? () from /lib64/libtcl8.6.so #8 0x00007fe160c42d4f in Tcl_ServiceEvent () from /lib64/libtcl8.6.so #9 0x00007fe160c43049 in Tcl_DoOneEvent () from /lib64/libtcl8.6.so #10 0x00007fe160f3a052 in Tk_MainLoop () from /lib64/libtk8.6.so #11 0x00007fe160f48c30 in Tk_MainEx () from /lib64/libtk8.6.so #12 0x000055633ed15b0c in main () Am perfectly willing to test debugging/instrumentation patches if needed. | |||
| User Comments: |
nemethi (claiming to be Csaba Nemethi) added on 2026-10-06 14:22:27:
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-09-18 20:50:36: An entirely elided line is laid out as its own zero-height display line, but fvogel added on 2019-01-19 15:30:45: The culprit commit [dd92553e654ab407] really is correct, otherwise some tests with elided text fail. The provided testcase uses a text widget to display 875300 lines of text, with many (4118, to be precise) ranges of elided text. The ranges of elided text consist in 3201 ranges of a single elided line, 732 ranges of two successve elided lines, 183 ranges of three successive elided lines, and two much larger ranges of 152 and 72888 lines. There is no infinite loop, only a very bad performance. The first 20 seconds (for me on the machine I'm using) are used to read the 'log_test' file from the disk and regexp-process this read text to remove some characters flagging some text lines. Then the resulting trimmed text gets displayed in the widget. From this point on, the CPU is used in the background to asynchronously update the line metrics, which is needed to get scrolling right. This background update really finishes if we wait long enough (I let it run and it really finished the job withing something between 2 hours and 8 hours - not sure exactly when since I tried during a night and was not in front of the machine when it finished). I think this problem is simply unsovable with the current (legacy) implementation. Handling of tags, and especially elided tags suffers from a know performance problem due to their implementation based on toggle segments. When looking for the elide state of an index, the widget has to search the segments in a complicated manner requiring triply-nested loops (see TkTextIsElided. However there is hope: this problem was solved in the revised implementation of the text widget. For details about the performance problem and how it has been overcome by the revised version, I suggest reading: - http://scidb.sourceforge.net/tk/new-tag-handling.html - http://scidb.sourceforge.net/tk/elide.html fvogel added on 2019-01-12 20:38:43: Many thanks to the anonymous poster having provided the test case "elide_test.tgz" on 11 Jan. 2019! This is a pure Tcl script (using some extension packages), and it really helps a lot! This allowed me to reproduce. I didn't analyze deeply what the provided script does, but it seems the "readtext.tcl" script reads a large (875300 lines) text file "log_test", and inserts its content into a text widget, with quite a lot of text tagged with -elide true. What I'm seeing on my computer running Windows, with 8.6.3:
What I'm seeing with 8.6.4:
Bisecting between 8.6.3 and 8.6.4 points at [486c2c231615967b] as the first failing commit. This commit is quite large. However that commit is a merge from the text-elided branch. Bisecting inside that branch points to [dd92553e654ab407] as the culprit. This is just two added lines. So we really made a lot of progress in the diagnostic. Now I'm pretty sure I can sketch a smaller test script showing the issue, and analyze the cause further. Final note: I have checked that the revised text widget does not suffer from this problem. fvogel added on 2015-11-10 07:04:57: ping? fvogel added on 2015-10-28 21:27:01: Between Tcl/Tk 8.6.3 and Tcl/Tk 8.6.4 I have fixed a lot of issues related to elided characters in the text widget (this work can be most easily seen in http://core.tcl.tk/tk/timeline?n=100&r=text-elided). These fixes touched the functions that are listed in your where output and may have broken something. However, this should not have changed the performance for text widgets not using elided characters (which is the case of exmh if I correctly grep-ed its source code). My first idea is to try to reproduce. I have now spent my evening at: 1. installing Fedora Rawhide in a virtual box: success, but then dnf-ing for the graphical environment makes VirtualBox crash --> I gave up 2. installing exmh-2.7.2 in an old Debian 6.0 I have at hand, and make it use Tcl/Tk from the latest fossil trunk (i.e. the bleeding edge of the continuing develoment past Tk 8.6.4) --> success, exmh starts up correctly. I do not see any high CPU usage. However I probably did not configure the mail system correctly since pushing the 'Inc' button does not show emails in exmh. I struggled for quite some time with fetchmail, exim, mh, mail, exmh installation and configuration, but I think I got lost (Linux is not my primary platform of choice). fetchmail seems to correctly retrieve the emails but then they do not show up in exmh (and I cannot find them anywhere else btw). Since I do not see the problem on my setup, a few proposals for a way ahead: a. The best would be to exhibit a short test case in pure Tcl/Tk demonstrating the issue. b. If a. is not directly possible, trimming down what exmh does could be done, but this looks difficult to me. Maybe exmh authors could help on this? c. Since you look like an experienced Linux user, I would suggest you fossil bisect the Tcl/Tk source code between 8.6.3 and 8.6.4, to identify the faulty commit. Then I could certainly find the error in the source code, fix it, and derive a simple test case that will later be turned into a non-regression test of the test suite. Thanks for your help! | |||
Attachments:
- elide_test.tgz [download] added by anonymous on 2019-01-11 14:58:11. [details]
