Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap-qt-apps-hooks leads to very slow wrapper scripts #225871

Closed
matklad opened this issue Apr 12, 2023 · 1 comment · Fixed by #225881
Closed

wrap-qt-apps-hooks leads to very slow wrapper scripts #225871

matklad opened this issue Apr 12, 2023 · 1 comment · Fixed by #225881
Labels

Comments

@matklad
Copy link
Member

matklad commented Apr 12, 2023

Describe the bug

Wrapper scripts for plasma apps such as krunner or plasma-emojier are slow. For example, executing just the wrapper for plasma-emojier takes 100ms on my fast machine.

The reason for slowness is that the wrapper itself repeatedly adds various paths:

$ rg -F "QT_PLUGIN_PATH='" $(which plasma-emojier) | wc -l
44

This leads to quadratic behavior. Profiling with perf shows that the bulk of the time is spend in string manipulation routines.

The relevant logic is here:

makeWrapper "$original" "$wrapper" "${qtWrapperArgs[@]}" "$@"

Essentially, we are calling

wrapProgram program \
  --prefix QT_PLUGIN_PATH ...
  --prefix QT_PLUGIN_PATH ...
  --prefix QT_PLUGIN_PATH ...

and makeWrapper then faithfully translates each --prefix, instead of pre-computing thee concatenation.

Steps To Reproduce

# Strip the `exec` line
$ <$(which plasma-emojier) head -n -1 > wrapper.sh && chmod a+x ./wrapper.sh

# Time the execution of the wrapper itself
$ time ./wrapper.sh
real	0m0.117s  😱
user	0m0.115s
sys	0m0.002s

Expected behavior

Wrapper itself shouldn't take more than a handful of milliseconds. It seems achievable if I manually replace incremental quadratic addition to environmental variables with setting them once.

Not sure what's the best fix here, some options I see are:

  • fix wrap-qt-apps-hook to pre-concatenate variables and pass just a single --prefix argument per variable to wrapProgram
  • make wrapProgram itself smarter and teach it to collate identical prefixes
  • fix wrap-qt-apps-hook to use --set rather then --prefix

As I don't know bash, I don't plan on working on the fix myself

Notify maintainers

cc @ttuegel

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[matklad@Ishmael:~/tmp]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.2.10, NixOS, 23.05 (Stoat), 23.05.20230411.3fb8eed`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.3`
 - channels(matklad): `""`
 - nixpkgs: `/nix/store/k9vs66va04886gl91m6lpcwaymqiihqx-9lkm36ac7hfl7f9h2z9dj00mdh30mjhi-source`
@matklad matklad added 0.kind: bug Something is broken 6.topic: qt/kde labels Apr 12, 2023
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/plasma-emojier-is-very-slow-makeqtwrapper-is-accidentally-quadratic/27160/3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants