Why indexOf kills large sheets
The pattern looks harmless at first: you have an array of already-processed IDs and call processedIds.indexOf(currentId) on every row. At 500 rows that's 250,000 comparisons in the worst case. At 20,000 rows it's 200 million. Apps Script has a hard 6-minute execution limit, and V8 runtime or not, you will hit it before you finish.
indexOf walks the entire array on every call — that's O(n²) growth. The script doesn't slow down gracefully; it just dies mid-sheet, leaving you with a half-processed dataset and no clean resume point.
The fix is a Set built once before the loop. Set.has is a hash lookup: O(1) regardless of how many entries are in it. Ten entries or ten thousand, the cost is the same.