Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Jan 12, 2021 04:17 AM
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?
Solved! Go to Solution.
Jan 12, 2021 09:02 AM
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.
Jan 12, 2021 06:37 AM
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.
Jan 12, 2021 08:05 AM
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.
Jan 12, 2021 08:17 AM
She stated in her initial post that she is using an automation, not script block/app. Automations must complete in 1000ms.
Jan 12, 2021 08:42 AM
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).
Jan 12, 2021 09:02 AM
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.
Jan 14, 2021 04:06 AM
Thanks. I am not sure what the problem was. It worked after I put code in line by line.
Jan 14, 2021 04:08 AM
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.
Jan 14, 2021 04:17 AM
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.
Jan 14, 2021 05:24 AM
Glad to hear you got this working!