All prime numbers (with the exception of 2 and 3) are multiples of 6, plus or minus 1. Given this, we only need to check these numbers for primality; no other numbers will be prime. In addition, instead of checking all prime numbers up to HALF of the number you are checking for primality, you only have to check until the SQUARE ROOT of the number. These facts, along with the optimizations made in Scratch 3.0 and the removal of the very long composites list, allow my prime checker to be significantly faster.
Source: https://en.wikipedia.org/wiki/Primality_test