mirror of
https://github.com/flatpak/flatpak.git
synced 2026-06-26 09:17:00 -04:00
Sourcing profile/flatpak.fish spawns `flatpak --installations` on every fish shell startup, which costs ~15 ms on a typical desktop and dominates fish's non-interactive init time when flatpak is installed. On any system where the login stack (pam_env, systemd user session, distro-specific init) has already populated XDG_DATA_DIRS with the canonical user flatpak export path, this spawn is redundant: the subsequent `contains` loop would be a no-op because the canonical entry is already there. Add a fast-path guard that checks for `$XDG_DATA_HOME/flatpak/exports/share` (falling back to `$HOME/.local/share/flatpak/exports/share` when XDG_DATA_HOME is unset) at the top of the script. When present, skip the slow path entirely. The slow path is preserved verbatim for sessions where the canonical entry is missing — e.g. a freshly-created user, or environments where session init hasn't populated XDG_DATA_DIRS yet — so custom installations configured via /etc/flatpak/installations.d/*.conf are still discovered in that case. Measured on Linux with `hyperfine --warmup 5 'fish -c exit'`: before: ~23 ms of startup spent in `flatpak --installations` after: ~10 us (a single `contains` check) on the common path.
27 lines
1004 B
Fish
27 lines
1004 B
Fish
if type -q flatpak
|
|
# Fast-path: skip spawning `flatpak --installations` when the canonical
|
|
# user installation's exports/share is already present in $XDG_DATA_DIRS.
|
|
set -x --path XDG_DATA_DIRS $XDG_DATA_DIRS
|
|
|
|
set -l __flatpak_xdg_data_home $HOME/.local/share
|
|
set -q XDG_DATA_HOME; and set __flatpak_xdg_data_home $XDG_DATA_HOME
|
|
|
|
if not contains -- "$__flatpak_xdg_data_home/flatpak/exports/share" $XDG_DATA_DIRS
|
|
set -q XDG_DATA_DIRS[1]; or set XDG_DATA_DIRS /usr/local/share /usr/share
|
|
set -q XDG_DATA_HOME; or set -l XDG_DATA_HOME $HOME/.local/share
|
|
|
|
set -l installations $XDG_DATA_HOME/flatpak
|
|
begin
|
|
set -le G_MESSAGES_DEBUG
|
|
set -lx GIO_USE_VFS local
|
|
set installations $installations (flatpak --installations)
|
|
end
|
|
|
|
for dir in {$installations[-1..1]}/exports/share
|
|
if not contains $dir $XDG_DATA_DIRS
|
|
set -p XDG_DATA_DIRS $dir
|
|
end
|
|
end
|
|
end
|
|
end
|