Tk Source Code

View Ticket
Login
Ticket UUID: 9438cce0bda58e031865eb9da8b221c128ee8bee
Title: Scrolling a frame in a canvas is very slow since TIP 262 (frame redrawn through a pixmap covering the whole frame)
Type: Bug Version: 9.0.0 and later
Submitter: nemethi Created on: 2026-05-26 19:46:16
Subsystem: 08. [(label)frame] and [toplevel] Assigned To: nobody
Priority: 5 Medium Severity: Severe
Status: Closed Last Modified: 2026-09-21 18:01:11
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-09-21 18:01:11
Description:

The attached file imagetest.tcl implements a minimalist scrollableframe, populated with 120 label widgets displaying the Tcl logo image logoLarge.gif. Start the script with Tk 8.6 and perform a scrolling at high speed, using the (vertical) scrollbar. The widget is scrolling quite smoothly and the images are being rendered in sync with the scrolling.

Now repeat the test with Tk 9.0.0 or later on Windows. This time the rendering of the images is lagging far behind the scrolling, and this results in many unacceptable artifacts, manifested in deformed images.

On macOS no artifacts are seen, but with Tk 9.0.0 or later, from time to time the scrolling becomes bumpy.

On X11 the behavior appears to be as expected.

This bug report was inspired by a similar example provided by Nicolas Robert, using SVG images and a third-party scrollableframe implementation. It has turned out that neither the image format, nor the scrollableframe implementation makes any difference.

User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-09-21 18:01:11:

Many thanks, Serhiy! Merged to main by commit [488cac36] and to core-9-0-branch by [48384e9f]. Closing the ticket.


serhiy.storchaka added on 2026-09-18 15:11:38:

This is not about images. Since [17cd34336f] (TIP 262) a frame is always drawn through a pixmap covering the whole frame, even without a background image, and a frame scrolled in a canvas is redrawn on every scroll step. Here the frame is 716x31440 pixels, so a pixmap of about 90 MB is allocated, filled and copied on every step. The same slowdown is seen with plain colored frames instead of images, on Linux too. Fixed on branch frame-no-pixmap in [45dcda3da9]: only frames with a background image or a labelframe label are double-buffered, as in 8.6. On Windows displaying photo images in labels remains 1.5-4 times slower than in 8.6; this needs a separate investigation.


marc_culler (claiming to be Marc Culler) added on 2026-05-28 15:07:46:
I don't see any signficant changes in the Windows image code between
8.6 and 9.1.  So I guess the next step would be bisection.

marc_culler (claiming to be Marc Culler) added on 2026-05-28 14:43:34:
I apologize for asking you to do this when I can easily do it myself.
The result is that changing the scaling to 1.0 on Windows has no effect on
the artifacts produced by the imagetest.tcl script.

My impression is that the issue with Windows is not related to speed, whereas
the issue with with scaling on linux XWayland is all about speed.  The display
can't keep up with the scrolling.  It is sort of amazing to me that X11 would
be so much faster than Wayland, given that Wayland is supposed to eliminate
lots of unnecessary network transactions and speed up the graphics.

Maybe the place to start is to see if there have been changes to the low level
image display code for Windows.

nemethi (claiming to be Csaba Nemethi) added on 2026-05-28 14:39:01:

Yes, I ran the test on Windows, too, with scaling 1.0 and with scaling 1.5. The result was in both cases a lot of unacceptably ugly artifacts.


marc_culler (claiming to be Marc Culler) added on 2026-05-28 13:45:27:
Thanks!  I think that points to inefficiency of scaling for high-dpi
displays as the source of the problem, but does not explain it.  Perhaps
it is a feature of XWayland, the X11 simulator included in Wayland.

However, I was most interested in whether setting the display scaling to
1.0 on Windows would make a difference.  Did you try that?

nemethi (claiming to be Csaba Nemethi) added on 2026-05-28 10:32:13:

I have repeated the test on all my Linux systems, and I can only confirm what I wrote yesterday:

  • On Ubuntu 26.04, which runs GNOME on Wayland, I see no issues if the display scaling is 1.0, and I see the gray window appearing from time to time if the scaling is different from 1.0.

  • On all the other systems, whose desktops run on Xorg, I can see no issues, regardless of the value of the display scaling.


marc_culler (claiming to be Marc Culler) added on 2026-05-27 21:20:46:
Casba, I think you should try running the script with display scaling 1.0 on
your various systems.  I think that would provide some clues.

nemethi (claiming to be Csaba Nemethi) added on 2026-05-27 15:44:08:

Now I have been able to reproduce the gray window without any images that you saw on Ubuntu. The tests that I made previously on several Linux variants ran on a screen with 1920 x 1080 px resolution and scaled to 150 %, except the one on Ubuntu 26.04, which was on an unscaled screen. Now I have repeated the test on Ubuntu 26.04, this time on a screen scaled to 150 %, and I could see the gray window. And now I can also explain, why: My Ubuntu 26.04 runs GNOME on Wayland, while all the other Linux variants that I have run their desktops on Xorg.

To macOS: My Mac Mini has an M1 processor, which is quite fast, but, of course, not as powerful as an M3. I see no artifacts, but sometimes the scrolling gets bumpy.

However, the most serious artifacts appear on Windows, regardless of whether the screen is scaled or not.


marc_culler (claiming to be Marc Culler) added on 2026-05-27 14:56:07:
I ran the test script on an M3 Macbook Air and saw no issues at all.
No artifacts; no bumpy scrolling.

marc_culler (claiming to be Marc Culler) added on 2026-05-27 14:00:46:
It may be relevant that my Ubuntu OS was running on a laptop with a
high-dpi EVO screen.  Were you testing on a high-dpi screen?

I am also not aware of changes to any low level image code, although
on macOS the change from drawRect to updateLayer could, in principle,
affect any graphics operations.  In the cases that I am aware of,
though, it has been an improvement.

However, one significant change was the effort to support scaling and
improve support for high-dpi screens.  That even affects macOS to
a small extent -- the switch to updateLayer required changes to XCopyArea
to make it aware of Retina displays. If displaying images in Tk 9 requires
scaling by a factor of 2 on high-dpi screens then that could slow
things down, especially if the scaling were being done on a pixmap
in CPU memory. (Not that I know at the moment how or when it is done -
I am just trying to narrow down what might be involved.)

nemethi (claiming to be Csaba Nemethi) added on 2026-05-27 10:45:58:

Thanks for your comments, Marc!

  1. I have repeated the test on Ubuntu Linux 26.04 (with GNOME on Wayland), Ubuntu Linux 24.04 (with GNOME on Xorg), KDE neon (running KDE Plasma on Xorg) , Xfce, and Cinnamon on Xorg. On none of these systems could I see the behavior with Tk 9.1 described by you. For me there was no perceptible difference in the performance of image rendering between Tk 8.6 and 9.x. The regression in Tk 9 is probably present on X11, too, but it is by far less dramatic than on Windows.

  2. I haven't stated that the culprit is the canvas widget. Actually, the scrollableframe used in the example provided by Nicolas is not canvas-based. I think, we can completely exclude the canvas as a potential cause of the bad behavior experienced with Tk 9 on Windows and to some extent on macOS.

  3. I suspect that there is some serious regression in the performance of image rendering in Tk 9, and its impact on the scrolling behavior is the worst on Windows.


marc_culler (claiming to be Marc Culler) added on 2026-05-27 03:44:36:

I am not sure what you expect for X11, but on Ubuntu with wish 9.1 your script looks much worse than it does with Tk 8.6. With Tk 9.1, while scrolling moderately quickly, I see a gray window without any images. When the scroll stops, the display catches up, and the images appear again. With 8.6 I see images throughout the scroll.

I am not aware of any changes to the canvas widget for Tk 9, however. Do you know of any?

There were changes on macOS to how scrolling works with the Text widget for Tk 9. In 8.6 scrolling a Text uses [NSView scrollrect: to:], which is deprecated by Apple. With the change to updateLayer we were able to replace that deprecated method with a call to XCopyArea.


Attachments: