I've got a Google Doc with Google Apps Script script running that multiple people contribute to. There is an onEdit
trigger that is fired when people edit the sheet. As I understand it, if one person edits the sheet this triggers my onEdit
trigger function.
If a second person edits the sheet before the first onEdit
finished processing then it stops the first instance and the second onEdit
starts without finishing the first one.
To avoid this I'm trying to make my code as efficient as possible with the theory that if the onEdit
process takes less time it's less likely to overlap. To accomplish this I've tried to minimize my read/writes. Using a series of logger statements I've tracked down lines of code that are time consuming. I've noticed that one of my setValues()
lines takes almost 6 seconds to run. It's a large array being posted back to the sheet after I've made adjustments to it.
My Questions:
- Does a
setValues()
call take longer than asetValue()
? - Does a
setValues()
call of a small array take less time than asetValues()
of a large array?
I know that one setValues()
will be much faster than 1000 setValue()
commands.
I had presumed one write to the sheet should take about the same amount of time regardless of size. Is there any way I can minimize this time?
LockService
– RaffDoes a setValues() take longer than a setValue()?
, it's no. A2: AboutDoes a setValues() of a small array take less time than a setValues() of a large array.
, it's yes. A3: AboutIs there any way I can minimize this time?
, how about using Sheets API? Ref – GennaLockService
, for example), both will run. So I am curious, what's your data source? Have you checked the executions tab? – DamagesetValues()
is size of your sheet. Make sure to delete empty rows at the bottom of every sheet. – RaffsetValue
to run on a sheet where you say thesetValues
method runs about 6 seconds? It is not unheard of that even a batch operation takes several seconds (in fact, it can take even more) if the size of the array is quite large. – Damage