It would indeed be better.

Here, you will have a different DQL cache key for each set of id and the DB will have a different SQL parsing cache again for each set. With a param, the DQL parsing would always get the same cache key (as the DQL would be the same) and the DB SQL parsing cache would only need an entry per length or the id array.