Bug 468328

Summary: Emoji Selector should be faster to launch
Product: [Plasma] plasmashell Reporter: Aleksey Kladov <aleksey.kladov>
Component: Emoji SelectorAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: wishlist CC: nate, waqar.17a
Priority: NOR    
Version: 5.27.4   
Target Milestone: 1.0   
Platform: NixOS   
OS: Linux   
Latest Commit: Version Fixed In: 5.27.5

Description Aleksey Kladov 2023-04-09 15:00:24 UTC
Emoji picker (`M-.`, `plasma-emojier`) is slow to start. It takes roughly 500ms between clicking the shortcut/starting the command in terminal, and the GUI window appearing. This is a very noticeable, flow-breaking delay. This is on a rather powerful desktop (i7-12700H, 1920x1080 display)

```
λ plasma-emojier --version
plasma.emojier 5.27.4
fish: Job 1, 'plasma-emojier --version' terminated by signal SIGSEGV (Address boundary error)
```

(sefault on version doesn't bother me :0)
Comment 1 Nate Graham 2023-04-10 18:59:31 UTC
If you run `plasma-emojier` in a terminal window, is it significantly faster to launch, or about the same? This will help us understand whether the issue is caused by the app itself being slow to launch, or whether the slowdown comes from the overhead of the global shortcut infrastructure.
Comment 2 Aleksey Kladov 2023-04-10 22:16:00 UTC
It’s slow either way, and other global shortcuts are pretty snappy
Comment 3 Nate Graham 2023-04-10 22:20:50 UTC
Ok, then it's the app.

FWIW it's pretty snappy for me with weaker hardware (i7-10510U). I can't reproduce any perceived slowness.
Comment 4 Aleksey Kladov 2023-04-10 22:23:31 UTC
Here's a firefox profile for `perf record`

https://share.firefox.dev/3ZQGasY

There's no symbols, but there's something taking 500ms there
Comment 5 Aleksey Kladov 2023-04-10 22:45:29 UTC
Got symbols:

https://share.firefox.dev/401bncW

It's pretty curious... Looks like the blame is actually on the NixOS wrapper script, which doesn't look at all reasonable: https://gist.github.com/matklad/a32bd2fc34bdb7edd37947d8d4619b35

I'll ask on nixos discourse what's up with that:

* either NixOS is doing something stupid there,
* or perhaps there's something lacking with plasma's dynamic linking/search path, which forces Nix to do a poorly perfoming work-aroud
Comment 7 Aleksey Kladov 2023-04-11 09:53:53 UTC
Taking a further look here, it seems like the slowness was the result of three independent causes:

* NiXOS quadratic QT_PLUGIN_PATH manipulation (I've eliminated it by constructing the right path myself)
* _Something_ in nvidia driver taking a lot of time to great a GL Context (eliminated that by switching to Intel)
* Residual slowness in emojier itself

With the first two issues fixed, the perf is improved to the point where it is not outright noticeable sluggish, but still doesn't quite feel instant. Though, at this point it is probably good enough. If anyone wants to poke at it, here's a profile: https://share.firefox.dev/3UqtTKC
Comment 8 Fushan Wen 2023-04-11 15:06:53 UTC
*** Bug 468386 has been marked as a duplicate of this bug. ***
Comment 9 Bug Janitor Service 2023-04-11 16:02:20 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/1469
Comment 10 Fushan Wen 2023-04-11 17:29:32 UTC
Git commit 24cce71ecc3167641f41fafe4da1a55ae1ece44d by Fushan Wen.
Committed on 11/04/2023 at 17:29.
Pushed by fusionfuture into branch 'Plasma/5.27'.

emojier: enable asynchronous loading in Instantiator

1. Using incubateObject to create GlobalDrawer greatly improves the startup time. 
2. Enable asynchronous loading in Instantiator, and update drawer.actions only when all actions are loaded. This reduces binding updates, hence further reduces the startup time.
FIXED-IN: 5.27.5

M  +0    -16   emojier/app/ui/CategoryAction.qml
M  +1    -1    emojier/app/ui/CategoryPage.qml
M  +70   -28   emojier/app/ui/emojier.qml

https://invent.kde.org/plasma/plasma-desktop/commit/24cce71ecc3167641f41fafe4da1a55ae1ece44d
Comment 11 Fushan Wen 2023-04-11 17:34:27 UTC
Git commit ffc8da9b4c4791a3dd662069eddb0be4c36cfcbc by Fushan Wen.
Committed on 11/04/2023 at 17:32.
Pushed by fusionfuture into branch 'master'.

emojier: enable asynchronous loading in Instantiator

1. Using incubateObject to create GlobalDrawer greatly improves the startup time.
2. Enable asynchronous loading in Instantiator, and update drawer.actions only when all actions are loaded. This reduces binding updates, hence further reduces the startup time.
FIXED-IN: 5.27.5
(cherry picked from commit 24cce71ecc3167641f41fafe4da1a55ae1ece44d)

M  +0    -16   emojier/app/ui/CategoryAction.qml
M  +70   -28   emojier/app/ui/emojier.qml

https://invent.kde.org/plasma/plasma-desktop/commit/ffc8da9b4c4791a3dd662069eddb0be4c36cfcbc
Comment 12 Aleksey Kladov 2023-04-12 23:15:07 UTC
> If you run `plasma-emojier` in a terminal window, is it significantly faster to launch, or about the same? 
> It’s slow either way, and other global shortcuts are pretty snappy

Spoke too soon @nate! After testing this patch, I found out that global shortcuts are also slow (global _application_ shortcut adds an extra 100ms delay in comparison to launching taskbar entry with the same shortcut).

See https://bugs.kde.org/show_bug.cgi?id=468440
Comment 13 Aleksey Kladov 2023-04-12 23:26:48 UTC
Also confirm that with

* NixOS [patch](https://github.com/NixOS/nixpkgs/pull/225881) applied
* emojier [patch](https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/1469) applied
* and using task manager shortcut, rather than M+.

plasma-emojier finally feels snappy enough for me!

Thanks!