I have a script that used to run in well under a minute. Recently I started getting "Exceeded maximum execution time" errors indicating it now breaks the 6 minute limit.
Using 'Execution transcript' I found that the few getValue() and getValues() calls I make take very long time, so I experimented.
The following test function takes anywhere from 3 to 7 seconds to execute:
function test_singleCellRange_getValue() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Marcin');
var range = sheet.getRange(1, 1);
var value = range.getValue();
}
The 'Execution transcript' shows that the getValue() call takes all the time:
[17-10-29 14:15:00:002 EDT] Starting execution
[17-10-29 14:15:00:019 EDT] SpreadsheetApp.getActive() [0 seconds]
[17-10-29 14:15:00:074 EDT] Spreadsheet.getSheetByName([Marcin]) [0.054 seconds]
[17-10-29 14:15:00:075 EDT] Sheet.getRange([1, 1]) [0 seconds]
[17-10-29 14:15:07:377 EDT] Range.getValue() [7.301 seconds]
[17-10-29 14:15:07:381 EDT] Execution succeeded [7.36 seconds total runtime]
The single cell contains a constant string value (i.e. no formulas). Is this dismal performance of getValue() normal (i.e. the new performance standard to expect from Google's servers), or is there something I can do to improve performance?
Performance of getValue() appears to be heavily impacted by the size of the spreadsheet. Even though the above code executes getValue() on a single cell range its performance appears to be impacted by the overall size of the spreadsheet.
This makes no sense - anyone has experience here? Is this how Google designed the API or is this a bug?
How about using Sheets API v4? Please think of this as one of several answers. When I deal with large data in Spreadsheet, I often use Sheets API because of the process speed. I don't know whether this sample script is useful for your situation. If this is not useful for you, I'm sorry.
This sample script can retrieve the same result with your script.
var sheetId = "### Spreadsheet ID ###";
var range = "Sheet1!A1:A1";
var value = Sheets.Spreadsheets.Values.get(sheetId, range);
// Logger.log(value.values)
In order to use this script, please enable Sheets API for Advanced Google Services and API console as follows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With