> this seems quite hard
I dunno, do matching against a hash table and only compare a short fingerprint. It'll be a meaningful speed up, usually be right. Fail in exceptional cases, and lose the performance advantage if you fix it.