Most of the time is spent maxing out the CPU in the Python process.
This change has two effects:
- lines are joined before being encoded (instead of encoding them one-by-one)
- larger network packets are sent, instead of a single packet per line
I don't know which affects the performance, but overall, this is
a consistent 25 to 35% speed-up to the overall run time of