Avoid spawning subprocesses on startup to probe graphical capabilities#167
Open
tyvsmith wants to merge 1 commit into
Open
Avoid spawning subprocesses on startup to probe graphical capabilities#167tyvsmith wants to merge 1 commit into
tyvsmith wants to merge 1 commit into
Conversation
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.
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>
There was a problem hiding this comment.
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_idto cheaply detect window-id capability without spawning subprocesses. - Updated initialization gating to call
__done_can_get_window_idinstead of executing__done_get_focused_window_idat 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 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 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 on lines
+83
to
+85
| or test -n "$SWAYSOCK" # Sway | ||
| or test -n "$HYPRLAND_INSTANCE_SIGNATURE" # Hyprland | ||
| or test -n "$NIRI_SOCKET" # Niri |
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The initialization code (line 200-202) calls
__done_get_focused_window_idon every interactive shell startup just to check whether the system can get a window ID. On macOS this spawns twolsappinfoprocesses (~20ms); on Linux/X11 it may spawnxprop.This PR adds a lightweight
__done_can_get_window_idfunction 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:type -q lsappinfotest -n "$SWAYSOCK"test -n "$HYPRLAND_INSTANCE_SIGNATURE"test -n "$NIRI_SOCKET"test "$XDG_SESSION_DESKTOP" = gnome; and type -q gdbustype -q xprop; and test -n "$DISPLAY"set -q __done_allow_nongraphicalThe 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/WSLInteropinstead.