Bug 510627 - "layer-thumbnails-stroke" KisIdleTaskStrokeStrategy blocks UI and freezes input
Summary: "layer-thumbnails-stroke" KisIdleTaskStrokeStrategy blocks UI and freezes input
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: * Unknown (other bugs)
Version First Reported In: git master (please specify the git hash!)
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-10-15 05:24 UTC by Ming Chuan
Modified: 2026-01-28 12:24 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ming Chuan 2025-10-15 05:24:55 UTC
SUMMARY

```
WARNING: idle task consumed more than 200ms, it can cause visible distractions to the user
WARNING: time consumed in "layer-thumbnails-stroke" is 1000ms
```

https://invent.kde.org/graphics/krita/-/blob/87ec67592d6fc7ed15a1b19d40e3a520738d29e9/libs/ui/KisIdleTaskStrokeStrategy.cpp#L51-65 is consistently triggered by "layer-thumbnails-stroke" action, when user have any non-trivial layer setup such as filter layers with many layers.

Krita becomes unresponsive and blocks user input, resulting in a poor user experience. A typical scenario looks like this

When the thumbnail computation is running, krita become unresponsive and blocks user input, causing bad user experience. Typical scenario:

1. User make a stroke
2. User thinks briefly to decide if the stroke is good or not, for 200ms (`4 * preferredIdleWatcherInterval()`).
3. "layer-thumbnails-stroke" KisIdleTaskStrokeStrategy starts running, blocks user input, sometimes more than 1000ms.
4. User presses undo while the thumbnail update is still running, and krita just ignores it. (Not even undoing after it unblocks)

I don't know if there is a valid reason for this thumbnail update to block user input or the event loop. Since it’s a low-priority background task, it should be possible to offload the computation.

A cheap workaround is to turn up `preferredIdleWatcherInterval()` to lower the chance of user hitting this.

STEPS TO REPRODUCE
1. Run something like https://gist.github.com/sifmelcara/987e0c3a2eee82ad5bd58dc3e4ec00f4 to get a non-trivial layer setup
2. Paint on the inner most paint layer while the layers docker is visible, observe the extreme lag
3. Paint in fullscreen mode, observe that the lag caused by thumbnail update is gone

You can also try change `preferredIdleTaskMaximumTime()` to lower the threshold of warning, to make the issue more visible in log.

SOFTWARE/OS VERSIONS

Note that this is a regression introduced to master branch, not in 5.2.13 release

ADDITIONAL INFORMATION
Comment 1 Halla Rempt 2025-10-15 07:24:59 UTC
Extra note:

07:41:16 < sifmelcara[M]> Hmm just found
                          https://invent.kde.org/graphics/krita/-/commit/572c64858d1b506ca1500b776cc49dfd65105ddd
                          and realize that the delay was actually reduced in order to speed up overview docker
                          update. The time-consuming layer thumbnails update scenario wasn't considered
Comment 2 Dmitry Kazakov 2026-01-28 12:24:46 UTC
Git commit 00e1b0fe9e5ba7c7b06599cd4f4892b469fd3b19 by Dmitry Kazakov.
Committed on 28/01/2026 at 12:24.
Pushed by dkazakov into branch 'master'.

Switch to coarse layer thumbnails when generation is slow

When a layer has vast areas of empty pixels, it may be slow
to calculate its exactBounds(). In this case, if thumbnail generation
takes more than 40ms, Krita will automatically switch the layer
into "coarse thumbnail generation mode" and use extent() instead.

The status bar will also show a warning symbol and list the "slow
layers" in a tooltip.

A proper solution to this problem will come later in this MR:
https://invent.kde.org/graphics/krita/-/merge_requests/2578

M  +6    -6    benchmarks/kis_thumbnail_benchmark.cpp
M  +25   -4    libs/image/kis_base_node.cpp
M  +30   -2    libs/image/kis_base_node.h
M  +7    -10   libs/image/kis_layer.cc
M  +2    -2    libs/image/kis_layer.h
M  +2    -4    libs/image/kis_mask.cc
M  +1    -1    libs/image/kis_mask.h
M  +11   -6    libs/image/kis_paint_device.cc
M  +5    -2    libs/image/kis_paint_device.h
M  +26   -7    libs/image/kis_paint_device_cache.h
M  +2    -4    libs/image/kis_selection_based_layer.cpp
M  +1    -1    libs/image/kis_selection_based_layer.h
M  +8    -0    libs/image/kis_types.h
M  +1    -1    libs/image/tests/kis_paint_device_test.cpp
M  +16   -2    libs/ui/KisLayerThumbnailCache.cpp
M  +10   -0    libs/ui/kis_config.cc
M  +9    -0    libs/ui/kis_config.h
M  +1    -1    libs/ui/kis_custom_pattern.cc
M  +1    -1    libs/ui/kis_node_model.cpp
M  +49   -2    libs/ui/kis_statusbar.cc
M  +1    -1    libs/ui/utils/KisFileIconCreator.cpp
M  +1    -1    plugins/dockers/advancedcolorselector/kis_common_colors.cpp
M  +1    -1    plugins/dockers/animation/KisAnimTimelineFramesModel.cpp
M  +1    -3    plugins/dockers/historydocker/KisUndoModel.cpp
M  +1    -1    plugins/dockers/widegamutcolorselector/WGCommonColorsCalculationRunner.cpp
M  +1    -1    plugins/tools/tool_transform2/kis_tool_transform.cc

https://invent.kde.org/graphics/krita/-/commit/00e1b0fe9e5ba7c7b06599cd4f4892b469fd3b19
Comment 3 Dmitry Kazakov 2026-01-28 12:24:54 UTC
Git commit a059548b007f99e32533c77e26f0d25650998027 by Dmitry Kazakov.
Committed on 28/01/2026 at 12:24.
Pushed by dkazakov into branch 'master'.

Add Image->Purge Unused Image Data

Under some conditions it might happen that some layers and/or
projections will contain vast areas of fully transparent data. It can
cause a lot of undesirable side-effects, like layer thumbnails
recalculating too slowly or image compositing being extremely
slow.

This patch adds a new user-faced action Image->Purge Unused
Image Data, which iterated through all existing layers and removing
all fully transparent areas.

Just a mere calling to this action can workaround the "slow thumbnail
generation" issue as reported in bug 510627. Hence calling to that also
switches all the layers back into "precise" thumbnail generation mode.

WARNING: calling this action can potentially break Undo/Redo for your
image. Please take that into account until the feature is fully tested.
CC:kimageshop@kde.org

M  +2    -1    krita/krita5.xmlgui
M  +12   -0    krita/kritamenu.action
M  +68   -13   libs/image/kis_image.cc
M  +14   -0    libs/image/kis_transaction.h
M  +11   -0    libs/ui/kis_layer_manager.cc
M  +1    -0    libs/ui/kis_layer_manager.h
M  +2    -1    libs/ui/kis_statusbar.cc

https://invent.kde.org/graphics/krita/-/commit/a059548b007f99e32533c77e26f0d25650998027