Fix quadratic performance in gen.engine when yielding a large list.