Skip to content

Avoid spawning subprocesses on startup to probe graphical capabilities#167

Open
tyvsmith wants to merge 1 commit into
franciscolourenco:masterfrom
tyvsmith:optimize-startup-probe
Open

Avoid spawning subprocesses on startup to probe graphical capabilities#167
tyvsmith wants to merge 1 commit into
franciscolourenco:masterfrom
tyvsmith:optimize-startup-probe

Conversation

@tyvsmith
Copy link
Copy Markdown

Summary

The initialization code (line 200-202) calls __done_get_focused_window_id on every interactive shell startup just to check whether the system can get a window ID. On macOS this spawns two lsappinfo processes (~20ms); on Linux/X11 it may spawn xprop.

This PR adds a lightweight __done_can_get_window_id function that uses only fish builtins (type -q, test -n) and environment variables to check capability — zero subprocess cost. The checks mirror each branch of __done_get_focused_window_id:

Platform Probe
macOS type -q lsappinfo
Sway test -n "$SWAYSOCK"
Hyprland test -n "$HYPRLAND_INSTANCE_SIGNATURE"
Niri test -n "$NIRI_SOCKET"
GNOME test "$XDG_SESSION_DESKTOP" = gnome; and type -q gdbus
X11 type -q xprop; and test -n "$DISPLAY"
Non-graphical set -q __done_allow_nongraphical

The actual window ID is already fetched on-demand in __done_started (fish_preexec) and __done_is_process_window_focused (fish_postexec), so the startup call was purely a capability gate.

Impact

Saves ~20ms of interactive shell startup time on macOS (measured with fish --profile-startup).

WSL note

The old code also had a WSL check (uname -a | string match microsoft), which itself spawns a subprocess. The new code omits this from the capability check — WSL users can set __done_allow_nongraphical + __done_notification_command, which is already the recommended WSL configuration. If WSL support is needed in the capability check without a subprocess, we could check for the existence of /proc/sys/fs/binfmt_misc/WSLInterop instead.

The initialization code calls `__done_get_focused_window_id` on every
shell startup just to check whether the system *can* get a window ID.
On macOS this spawns two `lsappinfo` processes (~20ms); on Linux/X11
it may spawn `xprop`.

Replace this with a new `__done_can_get_window_id` function that uses
only fish builtins (`type -q`, `test -n`) and environment variables to
check capability. The actual window ID is already fetched on-demand in
`__done_started` (fish_preexec) and `__done_is_process_window_focused`
(fish_postexec), so the startup probe was purely a capability gate.

This saves ~20ms of interactive shell startup time.
Copilot AI review requested due to automatic review settings March 19, 2026 01:24
tyvsmith added a commit to tyvsmith/dotfiles that referenced this pull request Mar 19, 2026
Use tyvsmith/done fork which replaces lsappinfo subprocess probe
with builtin type -q check on startup (~19ms saved).
Upstream PR: franciscolourenco/done#167

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes done’s fish-shell startup initialization by replacing a subprocess-heavy “can I get a window id?” probe with a lightweight capability check based on fish builtins and environment variables.

Changes:

  • Added __done_can_get_window_id to cheaply detect window-id capability without spawning subprocesses.
  • Updated initialization gating to call __done_can_get_window_id instead of executing __done_get_focused_window_id at startup.
  • Expanded inline documentation explaining why the new gate exists and where window IDs are fetched on-demand.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread conf.d/done.fish
Comment on lines +79 to +89
function __done_can_get_window_id
# Lightweight capability check using only builtins and env vars.
# Avoids spawning subprocesses on every shell startup (~20ms on macOS).
type -q lsappinfo # macOS
or test -n "$SWAYSOCK" # Sway
or test -n "$HYPRLAND_INSTANCE_SIGNATURE" # Hyprland
or test -n "$NIRI_SOCKET" # Niri
or begin; test "$XDG_SESSION_DESKTOP" = gnome; and type -q gdbus; end # GNOME
or begin; type -q xprop; and test -n "$DISPLAY"; end # X11
or set -q __done_allow_nongraphical
end
Comment thread conf.d/done.fish
Comment on lines +82 to +88
type -q lsappinfo # macOS
or test -n "$SWAYSOCK" # Sway
or test -n "$HYPRLAND_INSTANCE_SIGNATURE" # Hyprland
or test -n "$NIRI_SOCKET" # Niri
or begin; test "$XDG_SESSION_DESKTOP" = gnome; and type -q gdbus; end # GNOME
or begin; type -q xprop; and test -n "$DISPLAY"; end # X11
or set -q __done_allow_nongraphical
Comment thread conf.d/done.fish
Comment on lines +83 to +85
or test -n "$SWAYSOCK" # Sway
or test -n "$HYPRLAND_INSTANCE_SIGNATURE" # Hyprland
or test -n "$NIRI_SOCKET" # Niri
Comment thread conf.d/done.fish
or test -n "$HYPRLAND_INSTANCE_SIGNATURE" # Hyprland
or test -n "$NIRI_SOCKET" # Niri
or begin; test "$XDG_SESSION_DESKTOP" = gnome; and type -q gdbus; end # GNOME
or begin; type -q xprop; and test -n "$DISPLAY"; end # X11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants