From 716902f8e15239dae306bc68d8d859482e6cf12b Mon Sep 17 00:00:00 2001 From: The_miro Date: Thu, 9 Jul 2026 09:18:34 +0200 Subject: [PATCH] perf(astal-menu): use gdbus Activate fast path in menu-toggle.sh menu-toggle.sh always cold-started a second python3+PyGObject+GTK4 process to forward one verb to the already-running daemon, per GApplication's command-line-forwarding mechanism. That's ~0.5s baseline and spikes past 5s under load, easily read as an unresponsive/broken menu button on repeat taps. main.py's own do_command_line comment already describes the intended fix: call the registered org.gtk.Actions directly over D-Bus for an already-running instance. Wire that up (gdbus call, ~20-100ms) and keep the python3 spawn only as the cold-bootstrap path when no instance is registered yet. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01TLz6HWsXCwzQ97LrLt2em6 --- desktopenvs/hyprlua/scripts/menu-toggle.sh | 43 +++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/desktopenvs/hyprlua/scripts/menu-toggle.sh b/desktopenvs/hyprlua/scripts/menu-toggle.sh index c49f58f..6f57041 100755 --- a/desktopenvs/hyprlua/scripts/menu-toggle.sh +++ b/desktopenvs/hyprlua/scripts/menu-toggle.sh @@ -13,6 +13,7 @@ # Verbs: (toggle) | show | hide | appdrawer. Sides: top | bottom | left | right. BUS="eu.abdelbaki.astalmenu" +OBJ="/eu/abdelbaki/astalmenu" APP="${HOME}/.config/astal-menu/main.py" verb="${1:-}"; side="${2:-}" @@ -22,27 +23,43 @@ case "$verb" in esac case "$verb" in - appdrawer) VERB="--appdrawer" ;; - show) VERB="--show" ;; - hide) VERB="--hide" ;; - *) VERB="--toggle" ;; + appdrawer) VERB="--appdrawer"; ACTION="appdrawer"; HAS_PARAM=1 ;; + show) VERB="--show"; ACTION="show"; HAS_PARAM=1 ;; + hide) VERB="--hide"; ACTION="hide"; HAS_PARAM=0 ;; + *) VERB="--toggle"; ACTION="toggle"; HAS_PARAM=1 ;; esac case "$side" in top|bottom|left|right) SIDE=(--side "$side") ;; - *) SIDE=() ;; + *) side=""; SIDE=() ;; esac registered() { busctl --user list 2>/dev/null | grep -q "$BUS"; } -if ! registered; then - "${HOME}/.config/scripts/astal-menu-start.sh" >/dev/null 2>&1 & - for _ in $(seq 1 25); do - if registered; then break; fi - sleep 0.2 - done +if registered; then + # Fast path: the daemon is already up, so activate the action directly over + # D-Bus (~20-100ms) instead of cold-starting a second python3 + PyGObject + + # GTK4 process (~0.5s baseline, much worse under load — observed spikes past + # 5s) just to forward one verb via GApplication's command-line forwarding. + if [[ $HAS_PARAM -eq 1 ]]; then + param="[<'${side}'>]" + else + param="[]" + fi + exec gdbus call --session --dest "$BUS" --object-path "$OBJ" \ + --method org.gtk.Actions.Activate "$ACTION" "$param" "{}" >/dev/null fi -# If it still didn't register, this invocation just becomes the primary instance -# (Gio single-instance handles the routing either way). +# Not registered yet: start the daemon and wait for it to come up, then retry +# via the fast path above. +"${HOME}/.config/scripts/astal-menu-start.sh" >/dev/null 2>&1 & +for _ in $(seq 1 25); do + if registered; then + exec "$0" "$@" + fi + sleep 0.2 +done + +# Still not registered after 5s: fall back to becoming the primary instance +# ourselves (Gio single-instance handles the routing either way). exec python3 "$APP" "$VERB" "${SIDE[@]}"