To amortize the function call overhead I have changed my generator so that it yields a fixed-length list of a few values instead of yielding one value at a time. The generator, as it originally stood, unpickled an object from a file that contains several pickled objects, and yielded it. These were then processed inside a for loop that consumed the generator. This approach turned out to be a lot slower than having the object processing code inside a hand unrolled loop that unpickled several consecutive items in the file at a time. I am attempting a compromise. My modified generator yields a fixed-length list of pickled objects at a time. I am looking for a Pythonic way to unpack that packet of unpickled objects at the consumer side.
Is there a way to deconstruct those packets without having an extra nested loop ? I incorrectly assumed that the *
operator will do it like so:
for x in *packetizing_generator(): f(x)
Nested loop of course works, but am wondering if there is a shorter and more elegant way.