Optimized get_canonicals.

The function can now filter by lengths and is optimized for speed using
.tuple(), naive() and iterator().