Computer gradually slows down as KM macros runs, CPU usage reaches 100% after a few hours

Hello, I have written a macro that utilize screen condition/pixel condition frequently.
The macros is fast and efficient at the start, but as the macro keeps on running, it becomes slower and slower and the process with name “WindowServer” consumes more and more CPU power ( it reaches 100% CPU usage after some hours)
Whenever I move my mouse cursor, the CPU usage of “WindowServer” process jumps up and the computer slows down/freezes.
The situation continues even if the macro is no longer running (all macros are cancelled by Ctrl+Alt+Q ) and I can’t use other applications such as Office / Web Browser properly.
Things go back to normal only when I choose to quit the keyboard maestro engine completely or restart my computer, and the CPU usage of “WindowServer” drops back to single digit.
I really love to use Keyboard Maestro as it saves me a lot time and want to recommend my friends and colleagues to buy it too, but this problem is really annoying and time wasting to deal with.
Any help/suggestion will be greatly appreciated, Thank you!

I am using Macbook Air (13-inch,2012) OSX Yosemite 10.10.3
Keyboard maestro version 6.4.8

Typically, if Keyboard Maestro is not running any macro (including implicit ones for updating the editor display), the CPU usage is < 1%.

When running any macro, the CPU usage of the engine is typically 10-15% CPU unless the macro includes CPU intensive operations like searching the screen.

Generally, the only time you get high CPU usage out of Keyboard Maestro Engine is when it is searching the screen for an image (which is a highly computationally intensive task).

It will do this if you are executing a macro that requires this functionality (especially bad can be Pause Until since this will continuously check for the image). Check the Keyboard Maestro status Cancel submenu to see what macros are currently running, as well as the recently executed macros (select the All Macros group and sort the macros by macro execution).

If will also do this if there is an action editor displayed in the Keyboard Maestro editor which is live evaluating an expression involving searching the screen. Eg, an If Then Else action with a Screen Condition action. Since the displayed “(currently true)” or “(currently false)” condition is updated every second, even if the macro is not executing, if the condition is displayed in the Keyboard Maestro editor, it is still testing the screen.

Cancel the appropriate macros, add timeouts if necessary so they dont recur, and don’t leave the Keyboard Maestro editor displaying such an action (quit it, or undisclose the actions, or deselect the macro).

1 Like

Thank you very much for your help!
I have already checked the status cancel submenu to ensure that no macros are running and also quit the keyboard maestro editor to ensure that it is not detecting screen/pixel conditions. However, the process “WindowServer” is still eating up CPU time, this process’s CPU usage jumps up to 100% and freeze the computer for ~5 seconds whenever I try to move my mouse cursor.
The problem can be only solved by quitting the “keyboard maestro engine” process or restart the computer , but then I can’t run any macro I want if I do so.
After Googling a bit, I discovered that in fact many Yosemite users have the similar problem. In this stackexchange question WindowServer high CPU on Yosemite for example, it says the way to solve WindowServer process high CPU is to shut down applications on the menu bar that were making high frequency drawing updates. In their case it’s the “Network Monitor from Little Snitch”, in my case it’s “Keyboard Maestro Engine”.
I can’t manually shut down/restart KM engine everytime the problem occurs since I need to run my macros at night while I am sleeping, and it is annoying that when the problem arise at night it slows down the computer and macro executing speed, or even break the macro and left the job undone when I wake up next morning. I will try to add timeouts to the actions in my macros (particularly actions related to screen/pixel conditions) and see if it improves the situation.
Any ideas/suggestions are greatly appreciated, thank you.

The suggestions for solutions on that thread are all over the map.

I’ve got no idea what the issue is, or even how Keyboard Maestro Engine might be tickling whatever bug it is tickling in Yosemite/Window Server.

No idea what might help - its not something I have seen myself.

Thank you, I will try to follow the suggestions from other threads and post the result here if they work
update: I have tired to test different types of actions and see which action exactly is the culprit ( e.g. if then else with screen image condition, wait until image is found , if then else with pixel condition, etc)
I did this by choosing one type of action at a time and repeat it for 9999 times, then see which one slows the computer down after completion.
Surprisingly, It's not the action related to screen/image condition but the "insert text by typing" action slows the computer down and boost "WindowServer" process CPU usage over time.
I have uploaded the picture of actions I used and I would like to know if anyone else is able to reproduce the slowdown I experienced

Update 2: I found out that even macro as simple as this one:

can result in extension CPU usage of "WindowServer" process when repeated for enough of times. I will try to replace KM keystroke action with applescript counterpart and see if the same thing happens again.

Update 3: I replace the above macro with this one using applescript:

and the slow down no longer occurs! Hooray!!
I am going to replace all keystroke actions in all my macros with applescript and see if the problem will be gone forever. :smile: