-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tkinter with Tk 8.6.11 is slow on macOS #87677
Comments
Comparing performance of a Tkinter graphics program with Python 3.9.2 on an M1 Mac Mini, I find it to be slower than earlier versions, and much slower than the same program running on other computers such as a Raspberry Pi 3B (Python 3.7.3). Initial investigation suggests the slow down is because of Tk 8.6.11. Has anyone noticed similar? The program is simple & portable, downloadable from: |
An easy demo of the performance problem is to compare the execution speed of the single command:
in a python3 shell in a terminal window (it's real fast), I understand that IDLE3 uses the tkinter.py/Tcl/Tk toolset for windowing. There's something slowing it down on the M1 Mac Mini (MacOS 11.2.3), making it run much slower than on a Wintel PC or Linux Raspberry Pi. I don't know if the problem occurs with any Python versions other than 3.9.2 on MacOS. |
Thanks for submitting a very interesting issue! tkinter/Tk performance is not something we normally pay a lot of attention to. I did not attempt to run your application but I was able to see significant performance differences with your simple "help('modules') test. Before saying more, I want to test some additional configurations but I've run out of time for today. However, the differences don't seem to have anything to do with running on new M1 Macs as I was able to see them on a traditional Intel-based Mac running macOS 11. |
I spent a few hours running numerous configurations (M1 Mac Mini, iMac24-2007, Win10 on i5-8250U, Raspberry Pi 4B, various Pythons from 3.7.3 to 3.10.0a6). It can get confusing. The simplest qualitative performance test is just use
>>> help('modules') (in IDLE vs. python in a Terminal window)
though my TerraLunar.py graphics program can give quantitative results. The Turtle graphics demo programs in IDLE also perform slow on the M1 Mac. |
The result of help('modules') depends on Python version. Do you have any example which does not depend on Python version? Could you also run some pure Tcl/Tk demos to check whether the difference is in Tcl/Tk instead of the wrapper? |
Summary: "poor tkinter performance correlates with failed self-tests" I'm an amateur hobbyist noobie programmer, so sophisticated testing is a challenge for me. I raised this issue because I noticed Python graphics thru tkinter is especially slow on MacOS, and especially ultra-slow on my new M1 Mac Mini with Python 3.9.2 or 3.10.0a6 for Apple silicon. Aside from this weird issue, the M1 Mac outperforms all my other computers (including Win10 on i5-9500T, and Raspberry Pi 400). I'm expecting at least 10x performance improvement on M1 Macs when this issue gets resolved. Anyway, I looked under the hood. I found some tkinter test programs runnable on MacOS with: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/test/runtktests.py The same program is buried in the Windows Python modules library, but was not findable in Python 3.7.3 for Linux on Raspberry Pi. So I ran runtktests.py on Windows 10 and MacOS in many configurations. All was good EXCEPT Python 3.9.2 and 3.10.0a6 on old MacOS 10.11.6 and new MacOS 11.2.3. Those configs report about 10 Failed tests in a suite of over 1000 tests, and interestingly the 3.9 and 3.10 tests run about 4x slower than the older Python 3.8 tests that reported zero failures. So poor tkinter performance on MacOS correlates with failed tkinter self-tests. Maybe a more expert person could dig deeper? |
Failed tkinter tests were already noted in bpo-42507. |
This appears to be a Tk issue. I ran a benchmark (see attached) which repeatedly performed canvas actions. The first test ("clearing") clears the canvas, creates a rectangle, then calls both
A few notes:
|
I ran the bench.py and bench.tcl programs from E. Paine (epaine) on my M1 Mac Mini. Attached is a commented Terminal transcript. The tl;dr summary again is that Python 3.10.0a6 arm64 for Apple silicon is 3 to 100 times SLOWER than earlier pythons compiled for Intel x86-64 running with Rosetta2, when doing window operations thru Tcl/Tk. I have not yet attempted to install any version of Tcl/Tk independent of any Python or Apple build. I'm still learning slowly. And I am inspired to re-jig my little TerraLunar graphics program to run with python2.7 arm64. |
If this is a Tk issue we should report it in their bug tracker. I'm definitely against switching to an older version of Tk, the most recent release fixes a lot of problems with Tk on macOS. Correctness before performance. How bad is the performance compared to Tk on other platforms (with similar hardware)? |
One thing to look into: there appears to be a tk 8.6.11.1 release, I have no idea what changed in this micro release. |
The reduction in speed with later Tk versions does not seem to occur on Linux. See the below table (times are microseconds per iteration - tested using wish):
I have not tested on Windows but I don't think it's unreasonable to conclude the performance issue is limited to MacOS. |
This was the version I used when testing Wish on both MacOS and Linux. |
As this appears to be a Tk issue, I have created https://core.tcl-lang.org/tk/tktview/f642d7c0f4. |
tkinter performance on Windows 10 looks okay, no obvious problems. Attached is a transcript showing bench.py results for Pythons 3.8.2, 3.9.2, and 3.10.0a6 on Windows 10 on a Dell laptop with an Intel i5-8250U CPU (medium good speed, a good comparison to Apple M1 Mac). I originally raised this Issue because my new M1 Mac Mini performed so poorly compared to my Windows laptop, only for tkinter-related code. |
I have forked my TerraLunar graphics program to make a simpler more portable version, called "TerraLunar-tkbench.py" to facilitate testing of the tkinter stack for graphics performance. The project folder is at: https://github.com/ThomasWamm/TerraLunar-tkbench.git The folder includes results and commentary from running the program on numerous platforms (MacOS, Windows10, Raspberry OS Linux) and Python versions. Python 3.8.2 Tcl/Tk 8.5.9 TerraLunar-tkbench 0.1.8 runtime = 37 (arm64) Python 3.8.7 Tcl/Tk 8.6.8 TerraLunar-tkbench 0.1.8 runtime = 69 (x86_64) Python 3.9.2 Tcl/Tk 8.6.8 TerraLunar-tkbench 0.1.8 runtime = 69 (x86_64)
old iMac24-2007 MacOS 10.11.6 on 2.4 GHz Intel Core 2 Duo (x86_64) Python 3.7.3 Tcl/Tk 8.6.8 TerraLunar-tkbench 0.1.8 runtime = 381
Dell laptop Windows10 i5-8250U >= 1.6 GHz quad-core x86_64 Python 3.9.2 Tcl/Tk 8.6.9 TerraLunar-tkbench 0.1.8 runtime = 7 # Windows10 seems to be the best environment for tkinter.py / Tcl / Tk graphics apps. Every Mac platform is sadly much slower than a comparable Windows platform, for tkinter graphics. But the new M1 Mac platform is the slowest by far, slower than even a much older Intel Mac running the same versions of Python 3.10.0a6 and Tk 8.6.11 That's enough involvement for this noobie; I've now learned how complicated this performance issue is. It's not on my critical path, so I'm going back to my regular project far removed from tkinter graphics. Good Luck folks! |
According to Tk people, the regression in performance was unavoidable and the solution is to avoid relying on update in a loop: https://core.tcl-lang.org/tk/tktview/f642d7c0f4 |
@ned-deily : I propose closing this issue because this an issue with Tk and not something we can fix in CPython. |
Looking at the difference between macOS and Linux (4 vs 200!), it seems to me, that Tk "cheated" on macOS. Now it "cheats" less. |
I agree. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: