I can imagine that calling
keys in scalar context for a tied hash is really slow — as slow as the loop for the actual job, later on. Therefore, perhaps I should keep a running counter, and postpone the test until after everything is done. The season for the test is really because I collect $keep items without sorting them. In this case, we need a final
sort.
Perhaps we can do a final sort in any case, and skip keeping the counter.