I have a very large application, written in TypeScript
, using Visual Studio Community
, that I publish using CLASP
. At times, part of this application can run very slow and cause the script to be terminated. I’m trying to figure out what is causing these timeouts.
-
I tried writing to the log and viewing the results in
Executions
.This let me see where the script was, when it timed out, but it really didn’t highlight which portions of code were slowing things down.
-
I put a timing log together, in hopes of tracking down performance issues.
function doSomething() { let timer = new Timer(); // Do Something timer.stop(); }
The
Timer
object automatically identifies the function by parsing the stack and records the starting timestamp. Thestop
method records the ending timestamp and appends a row to aTIMING_LOG
Sheet in the current Spreadsheet.This worked well in small tests, but I soon realized that the overhead of adding just a single row of data to a single sheet, was way too high! I wouldn’t be able to log each timing log in real-time.
-
I altered the
stop
method to simplypush()
the timing log data into an array. The I add all those log lines to theTIMING_LOG
Sheet, before the operation completes.this.LogSheet .getRange( this.LogSheet.getLastRow() + 1, 1, this.mLogLines.length, this.mLogLines[0].length ) .setValues(this.mLogLines); this.mLogLines = [];
This works surprisingly well, but unfortunately, the lines of the log don’t get appended when the script times out.
What I’m looking for is some sort of signal, telling me that the script is being terminated. Like an event I can add a handler for. Something like…
GoogleAppScript.addEventListener("terminating", handleTermination);