An exit is not a cure
transcript
A duplicate check stops at the first repeat. So surely it must be fast. Let us count its comparisons. The answer depends on the input.
Put two equal ids at the very front. The check makes one comparison, and it stops. That is the best case for this check. It is the case an exit was made for.
Now use a thousand ids that are all different. No pair is equal, so the exit never fires. Every id is compared with every earlier id. That is four hundred ninety nine thousand five hundred comparisons.
The exit helps batches that hold a repeat. It does not help a clean batch at all. So the worst case stays exactly as it was.
Set the budget with the clean batch in mind. A repeat is a bonus, not a plan. Count the worst input before you ship.
An early exit is luck, not a cure. Full breakdown in the lecture.