Bug 465671 - KWin Wayland hangs for a second while launching browser with Junction
Summary: KWin Wayland hangs for a second while launching browser with Junction
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: wayland-generic (show other bugs)
Version: 5.26.90
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-13 15:27 UTC by hexchain
Modified: 2023-11-13 16:26 UTC (History)
2 users (show)

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


Attachments
reproducer.js (230 bytes, text/javascript)
2023-02-13 15:27 UTC, hexchain
Details

Note You need to log in before you can comment on or make changes to this bug.
Description hexchain 2023-02-13 15:27:32 UTC
Created attachment 156194 [details]
reproducer.js

SUMMARY
When using Junction (non-flatpak) to start the browser, the whole desktop freezes for less than a second before the browser shows up. This does not happen when it's running inside Flatpak.

I've nailed down the problem and attached a simple reproducer script.

STEPS TO REPRODUCE
1. Execute the script with GJS: gjs test.js

OBSERVED RESULT
Upon executing the script, the whole screen freezes for about a second.
This can be verified with some animated/moving things, e.g. glxgears or simply moving the mouse.

In the journal, kwin_wayland prints some warnings from kf.services:

kwin_wayland[1398775]: kf.service.services: The desktop entry file "/usr/share/applications/qemu.desktop" has Type= "Application" but no Exec line
kwin_wayland[1398775]: kf.service.sycoca: Invalid Service :  "/usr/share/applications/qemu.desktop"
kwin_wayland[1398775]: kf.service.sycoca: The menu spec file ( "" ) contains a Layout or DefaultLayout tag without the mandatory Merge tag inside. Please fix it.

EXPECTED RESULT
The screen should not freeze.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.26.90
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Kernel Version: 6.1.10-arch1-1 (64-bit)
Graphics Platform: Wayland
Comment 1 Nicolas Fella 2023-02-13 16:56:44 UTC
The problem is this:

app.set_as_last_used_for_type(mimeType) touches .config/mimeapps.list. It doesn't actually change anything, but it updated the lastmodified timestamp.

When an app is started KWin uses KService to check for the X-KDE-Wayland-Interfaces in the app's desktop file. KService notices that mimeapps.list was touched since the last time it used it and rebuilds its cache. That takes about a second and causes the freeze
Comment 2 Vlad Zahorodnii 2023-02-15 09:48:23 UTC
Is there something that we can do from kwin or kservice?
Comment 3 hexchain 2023-02-16 16:22:00 UTC
Is it possible to make the sycoca build process async? For example, if the timestamp mismatches when querying, then query against the stale database until it is rebuilt.

Or, is it possible (or desirable) to make KService a standalone DBus service? Currently, every application using KApplicationTrader::query has to scan all desktop files sometimes. That sounds like a lot of duplicated effort.
Comment 4 Nicolas Fella 2023-02-16 17:50:42 UTC
> Is there something that we can do from kwin or kservice?

KSyscoca::disableAutoRebuild would prevent the rebuild, but then the results won't be correct if something changes
Comment 5 hexchain 2023-11-12 05:57:27 UTC
This is no longer happening for me with KWin git master (835d6f4bc68a7e88b486daeec6712570a3a237a4).