[Feature request] Run heavy tasks in dedicated threads to prevent stutters and freezes

Currently kwin_wayland does almost all tasks synchronously in the main thread, which is an issue in term of performances especially when kwin loads things such as effects at runtime, or interacts with clients that give heavy tasks to the compositor. As a Plamsa-Wayland user, I see to many scenario where kwin drop frames, including the mouse cursor even if hardware cursor is enabled. It’s very noticeable on a high refresh rate monitor.
Examples of freezes:

These performance issues happens only in a Wayland sessions. With Xorg, a least the cursor is always smooth.
Here is a proposal of the thread architecture:

  • A dedicated thread for input management and cursor position.
  • A dedicated thread for the kwin render.
  • A thread pool to manage threads for applications interactions, effects and other heavy tasks.
  • A KMS thread (already implemented).
  • A dedicated thread for window management.
  • The main thread should only be used for kwin initialization/termination and thread management.

I know all of that is hard to implement and can’t be implemented straight away, but this is just to give an idea to how I see performance issues in kwin_wayland and I hope my advice will help KDE developers to improve kwin which is an incredible project.

2 Likes

Alt-tabbing is causing micro-freezes

My issue isn’t a micro-freeze. It takes 2.5 seconds after pressing Alt-Tab to see the list of windows, and another 2.5 seconds after selecting a window.

I’m wondering if the suggested threading idea will actually help, since I’m still waiting 2.5 seconds for something unknown.

After restarting kwin_wayland the issue is gone.
Unselecting “Show selected window” under System Settings > Task Switcher was solving the issue as well.
Uptime of machine is 9 days.