Long running script starts to eat a lot of CPU and slows down Script Editor

I have a script that runs for several days (or more) (it is an infinite loop) at the time. After a day or two it starts to slow down Script Editor/makes Script Editor eat a lot of CPU (the script is not CPU hungry by itself). How can this be avoided/remedied?

Why not run it with osascript?

(1) Appropriate waiting time

Infinite loop have to execute with appropriate waiting time (delay).
This is a kind of idea to not consume too much CPU processing time.

(2)Data enlargement

If the program store some data to property, the amount of whole data will be a large one. Very large data without high-speed handlling consume a lot of CPU time.

(3)Inappropriate runtime program

Beginner scripter sometimes run AppleScript on Script Editor with logging.
It will consume more CPU time and memory.
Script Editor or some development program sonsume large memory.
Small runtime program such as applet or droplet will be recommended.
You should avoid some insufficient function runtime program such as osascript which has not GUI Scripting permission.

(4)Quit the program at appropriate intervals

Some types of programs continue to increase memory usage.
A type of program does not cause any problems in short -term execution, but may cause a long -term execution.
We does not know about your whole script and related other programs.
The cause of the speed decrease may be the Script side, a runtime program, or other GUI application.
They will refresh if they terminate every execution.

(5)Inappropriate routine for data size

ASOC routine runs fast for large size data. But it does not run fast with smaller size data. Sometimes we had strange experience to increase performance in changing ASOC routine to vanila AS routine.
We have to select appropriate routine for each data size.

(6)Slowness due to CPU heating

Intel CPU got hotter and hotter when it work very hard.
As the CPU heats up, it slows down for safety. It’s called thermal throttling.
We need to cool our Macs properly.
Apple Silicon Macs have the same heat issues as Intel Macs, but if you don’t use a higher-end SoC, you probably don’t need to worry too much.

1 Like

Another issue that can lead to increased hard drive and CPU performance is a possible memory leak. For example, when AsObjC code works with large amounts of data, memory leaks sometimes occur and accumulate.

To prevent this accumulated data from being lost, the system kernel intensively swaps data between RAM memory and hard DISK memory. You can understand this by hearing the increased work of the drive.

In short, look for the cause in your script. Well, unless your computer got a virus, which is unlikely.

It would be nice if you posted your script so we can see what’s going on.

1 Like

Because of this Difference between Script Editor and osascript when using Keychain to send Apple Events to computer on the network

:frowning: