Skip to content

⚡ [performance improvement] Bypass cmd.exe for powercfg execution in Powerplan.ahk#39

Merged
Ven0m0 merged 1 commit intomainfrom
jules-9118704771034157626-e2536b92
Mar 1, 2026
Merged

⚡ [performance improvement] Bypass cmd.exe for powercfg execution in Powerplan.ahk#39
Ven0m0 merged 1 commit intomainfrom
jules-9118704771034157626-e2536b92

Conversation

@Ven0m0
Copy link
Copy Markdown
Owner

@Ven0m0 Ven0m0 commented Mar 1, 2026

💡 What: Modified Run() calls in ahk/Powerplan.ahk to directly execute powercfg.exe instead of passing the command string through cmd.exe /c.

🎯 Why: Launching an intermediate shell process to execute a standalone system command adds unnecessary CPU overhead, an additional process spawn, and memory allocations. Executing the executable directly avoids the overhead of spawning the cmd.exe middleman.

📊 Measured Improvement:
Since this Linux environment lacks Windows or Wine to run AutoHotkey directly, empirical dynamic benchmarking was not feasible. However, this is a well-established theoretical optimization in process execution:

  • Baseline: Spawns cmd.exe -> cmd.exe parses string -> cmd.exe spawns powercfg.exe -> returns to AHK.
  • Improved: Spawns powercfg.exe -> returns to AHK.

By cutting out the shell process allocation, the CPU cycles spent parsing and launching cmd.exe are entirely eliminated, yielding lower latency and overhead for the power plan switch operations.


PR created automatically by Jules for task 9118704771034157626 started by @Ven0m0

…Powerplan.ahk

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 1, 2026 06:29
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copy link
Copy Markdown
Contributor

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

Updates ahk/Powerplan.ahk to reduce process-spawn overhead during power plan switching by executing powercfg directly (instead of routing through cmd.exe /c), aligning with the repo’s low-latency automation goals.

Changes:

  • Replaced Run(A_ComSpec . " /c " . ...) with Run(...) for the power plan switch commands.
  • Eliminated the intermediate cmd.exe process spawn for powercfg execution.

Comment thread ahk/Powerplan.ahk
Comment on lines +36 to +40
Run(cmdOnLaunch, , "Hide")
fortniteWasRunning := true
}
else if (!fortniteIsRunning && fortniteWasRunning) {
Run(A_ComSpec . " /c " . cmdOnClose, , "Hide")
Run(cmdOnClose, , "Hide")
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

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

Now that the command is executed directly (not via cmd.exe /c), Run(cmdOnLaunch)/Run(cmdOnClose) depends on resolving powercfg via PATH and will throw an exception if the executable can’t be located/started (whereas cmd.exe would still launch and just return a non-zero exit code). Consider resolving powercfg.exe up front (e.g., via MustGetExe() from Lib/v2/AHK_Common.ahk, with a System32 fallback) and running using the resolved full path, and/or wrapping the Run() calls in try/catch so a transient failure doesn’t terminate the persistent loop.

Copilot uses AI. Check for mistakes.
@Ven0m0 Ven0m0 merged commit 91c42ec into main Mar 1, 2026
7 of 8 checks passed
@Ven0m0 Ven0m0 deleted the jules-9118704771034157626-e2536b92 branch March 1, 2026 07:43
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