Optimizing Google Sheets Script for Adding Dropdowns and Formulas to Multiple Rows

I’m working on a Google Sheets script where I need to dynamically update a sheet with dropdown menus and apply specific formulas to rows based on certain conditions. My current approach involves iterating over an array of objects (maintainedProcesses), setting formulas for “Destination Unit” and “Responsible Manager” columns if they are not already set, and then updating the sheet with these changes. Additionally, I create dropdown menus for several columns using validation rules based on data fetched from another sheet (“Data Validations”).

Here’s the relevant portion of my code (simplified and generic for clarity):

maintainedProcesses.forEach((process, index) => {
  const rowIndex = index + 2; // Adjust for header row
  if (!process['Destination Unit']) {
    process['Destination Unit'] = `=IFERROR(VLOOKUP(C:C;'Data Validations'!A:B,2,0);"")`;
  }
  if (!process['Responsible Manager']) {
    process['Responsible Manager'] = `=IFERROR(IF(E${rowIndex}="Screening";AA${rowIndex};"");"")`;
  }
});

await sheetManager.updateSheet(maintainedProcesses);

// Fetch validation data
const validationData = await sheetManagerValidations.readToJson();
const judicialActions = [...new Set(validationData.map(item => item['Judicial Action']))];
const subjects = [...new Set(validationData.map(item => item['Subject']))];
// etc. for other dropdowns

// Set dropdown menus
await sheetManager.setDropdownMenu(judicialActions, 'Judicial Action');
await sheetManager.setDropdownMenu(subjects, 'Subject');
// etc. for other dropdowns

The setDropdownMenu method is defined as follows:

async setDropdownMenuOld(options, columnName) {
  // Validation and setup omitted for brevity
  const rule = SpreadsheetApp.newDataValidation().requireValueInList(options).build();
  this.sheet.getRange(firstLine + 1, columnId + 1, lastLine - 1, 1).setDataValidation(rule);
}

While this code works, the process of adding each dropdown menu sequentially feels slow, especially with a large number of rows or when multiple dropdowns are involved. I’m looking for ways to optimize this process, ideally allowing for faster execution and possibly adding all dropdowns in a more efficient manner.

Is there a better approach or best practice for applying these kinds of updates to a Google Sheets document via Apps Script, particularly for reducing the time it takes to add dropdowns and formulas across many rows?

Comments:

I’m particularly interested in any strategies that can batch these operations or make them more efficient.
My environment is Google Apps Script with access to the Google Sheets API.
Thank you for your insights!