Hide rows where column F is not empty
In order to improve the performance of your script you should read cell values from an array that represents the entire range that your are going to scan.

This means that instead of repetedly calling


var status = sheet.getRange("F"+i).getValue(); //Get the value of the cell.



you should get everything in a single call like this one

var values = getRange(row, column, numRows, numColumns).getValues();


it'll give you an array that you can iterate very fast. Example:

for (var row in values) {
  for (var col in values[row]) {
      ...
  }
}




Hiding rows can be a little bit tricky if you want to optimize it becasue it requries some additional work. If you do it for each row separately then you'll loose some performance agian. This means that this is not good:


sheet.hideRows(i); // Hide the row



In my scripts that work with a few hundereds or thousands rows hiding some of them lasts no longer than 1-2 seconds.

Here's how it goes:

I have a special column that I call Visible (or whatever). I use it to store a boolean value.

When I run a loop I store the flag in a second array like var visibles = []; instead of calling hideRows each time.

After the loop is finished I update the Visible column with:

// update row visibility
var visibleRange = sheet.getRange(row, column, numRows, numColumns);
visibleRange.setValues(visibles);


This runs super fast.

Next you have to unhide all rows with:

// show all rows
sheet.showRows(rowIndex, numRows);


You have to sort them by visibility:

// sort by 'visible' and make 'true' (visible) rows first
sheet.sort(..., false);  


Sorting is necessary so that you can finally hide an entire range in a blink of an eye:

// hide 'false' (not-visible) rows
var rangeToHide = sheet.getRange(.., .., ..);
SpreadsheetApp.getActiveSpreadsheet().hideRow(rangeToHide);


If you need a different order you can sort it again after hiding.

With this solution it requires just a couple of calls which will make your script really smooth.



You can read about a couople more optimization tipps on Google Apps Script - Best Practices