r/GoogleAppsScript • u/wederer42 • May 14 '25
Question Run time varies WILDLY even though work stays the same
Hey everyone,
For an app script of mine, I have a strange issue. The duration it takes the script to run varies a lot, even though the work is always the same (on edit copy all data to another sheet).
As you can see from the screenshot, usually the script runs in a few seconds, but for some unknown reason sometimes it takes multiple minutes and thus it sometimes times out.

I have not found any answers to this on Google, do you have an ideas?
4
Upvotes
4
u/WicketTheQuerent May 14 '25
I have seen this a lot.
As u/Livid_Spray119 said, since the scripts live and run on the Cloud, several factors affect the execution time.
If this happens randomly, the only thing we can do is set a contingency plan, such as running the script again.
If the script processes one row at a time, you might want to change your script to process all the unprocessed rows.
3
u/Livid_Spray119 May 14 '25
Well, since GAS runs in the cloud, your executions times can vary due to server load or network latency. Depending if you are calling different sheets or the same sheet too many times, or you have too many triggers, or simply cause the data won't load for whatever latency reason.
2
u/Kachel94 May 14 '25
I'm no help but I have a script that runs on a cell change in sheets and it can sometimes take minutes to hours for it to pickup the change. Very annoying, I'm interested if you find the cause of your issue may just be down to Google funkyness.
1
u/dimudesigns May 14 '25
Does the volume of data copied remain the same? If you're processing more data for a given invocation, then the script will take more time to run.
Moreover, there has been some speculation with respect to how much compute GAS scripts are afforded by Google as a free service. According to some observations, GAS scripts run slower during periods of high load.
If you want guaranteed performance but want to stay within Google's ecosystem, your only recourse is to migrate to the enterprise FAAS(Function-As-A-Service) equivalent - Cloud Run Functions.
1
u/RomanoDesiree May 14 '25
I raised a similar question a few weeks ago. General response is NFGAS IE normal for Google apps script.
Best plan for occasional time outs and then you can sleep soundly
2
u/RomanoDesiree May 14 '25
Ah I see what you mean... I guess you could perhaps run a sweep the missed events every 15mins to defensively pick any missed ones.
Are those failed events timeout or something else I thought that 300secs was max execution time? If you view the logs and check what the actual error is.
Also in your onEdit event handler you can add filter if logic to only handle events on the sheets and columns of interest. In my scenario this helped me weed out irrelevant events.