Fix: CPU Time Exceeded

Hi there -

Currently, I am trying to do a data automation script to check if values meet specific criteria and then make recommendations for what is there vs what isn’t. The script is working as intended, however my CPU time is exceeded (3438 ⁄ 1000ms).

Any recommendations on how to fix?

It is very hard to speed up a script without seeing the actual code.

However, the most common culprit for slow automation scripts is updating or creating records one at a time instead of in batches.

Depending on what your script does, there are other possible ways of tweaking scripts to improve performance. Sometimes a script can be made faster by reworking the logic of the script. However, all of these types of adjustments require seeing the actual code.

If your code is short, you could try posting it to see if anyone spots anything. If your code is very long or you do not want to post it publicly, you could hire someone to do a private code review.

1 Like

I’ve taken the script block into some seriously CPU-invasive territory at very high scale and I have never encountered this issue. As such, my hunch is there’s something in your script that is creating some sort of race condition.

She stated in her initial post that she is using an automation, not script block/app. Automations must complete in 1000ms.

Oops! My bad. That matters a bunch.

Okay, so with that, assuming optimization of the script is complete, she likely needs to run that script elsewhere but very difficult to recommend where without seeing what happens in the steps following the script and the script itself.

Assuming the script is the final step, the analysis could be executed in Autocode, or Google Apps Script. In each of these approaches, you’d set up an HTTP POST that informs the script “service” to process the task for a given record (or collection of records). The service would call back into the tables for the data, perform the assessment, and then create whatever recommendations it needs (however that is achieved).

If these assumptions are correct, you have some great suggestions, but @Rose_Haft1 may want to consider a professional code review before assuming that the script is already producing the desired output as fast as possible. Many people do not have your (Bill’s) expertise in writing efficient code.

By the way, a programmer once told me to never optimize code. He was very successful at making legacy code run faster by removing optimizations. He had a quirky definition of “optimize” that others may not share. However, the point of my story is that getting the desired output faster can take finesse that isn’t always obvious.

1 Like

Thanks. I am not sure what the problem was. It worked after I put code in line by line.

1 Like

Hi Bill and @kuovonne - I’ve had my scripts crash a few times. I assume I am either hitting an infinite loop or computation too fast. So the CPU computation time is a problem in scripts but not exclusively.

Yep - my original hunch was a race condition, which is technically the latter and is likely caused by too many simultaneous computation threads. Non-blocking javascript can be a double-edged sword.

Glad to hear you got this working!

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.