From 7e1d33371689637d8db92b903a798bf4b99a8c14 Mon Sep 17 00:00:00 2001 From: Ven0m0 <82972344+Ven0m0@users.noreply.github.com> Date: Sun, 1 Mar 2026 06:30:35 +0000 Subject: [PATCH] perf: Replace polling loop with event-driven WinWait Optimizes `ahk/Powerplan.ahk` by removing an infinite loop that checked `WinExist()` every 5000ms. Replaced it with native `WinWait` and `WinWaitClose` logic. This reduces idle CPU utilization, entirely eliminates the 5-second polling latency when the target window state changes, and simplifies the codebase by removing state-tracking booleans. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- ahk/Powerplan.ahk | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/ahk/Powerplan.ahk b/ahk/Powerplan.ahk index cb7ef9a..2dbdd9e 100644 --- a/ahk/Powerplan.ahk +++ b/ahk/Powerplan.ahk @@ -25,21 +25,10 @@ cmdOnLaunch := "powercfg /s 8fcdad7d-7d71-4ea2-bb4c-158ca7f696de" ; Balanced power plan GUID cmdOnClose := "powercfg /s 77777777-7777-7777-7777-777777777777" -; Track previous state -fortniteWasRunning := false - Loop { - fortniteIsRunning := WinExist("ahk_exe FortniteClient-Win64-Shipping.exe") - - ; Only run command when state changes - if (fortniteIsRunning && !fortniteWasRunning) { - Run(A_ComSpec . " /c " . cmdOnLaunch, , "Hide") - fortniteWasRunning := true - } - else if (!fortniteIsRunning && fortniteWasRunning) { - Run(A_ComSpec . " /c " . cmdOnClose, , "Hide") - fortniteWasRunning := false - } + WinWait("ahk_exe FortniteClient-Win64-Shipping.exe") + Run(A_ComSpec . " /c " . cmdOnLaunch, , "Hide") - DllCall("kernel32.dll\Sleep", "UInt", 5000) + WinWaitClose("ahk_exe FortniteClient-Win64-Shipping.exe") + Run(A_ComSpec . " /c " . cmdOnClose, , "Hide") }