go-sql-driver/mysql — pull request #134 by julienschmidt (2013-10-23 12:45:02+00:00)
Title: Use the Connection Buffer for Writing

Instead of allocating multiple small new slices and copy them in one big slice before sending (current approach) or the 2-Pass approach (Pass 1: getting the total size; Pass 2: packing in a new allocated slice with perfect size) in #71, this PR introduces yet another approach:

The connection buffer (currently only used for reading) is used for packing until the the buffer gets too small. At this point we (the builtin func append) starts allocating bigger slices. This happens only for very large Queries since the buffer is by default 4KB large and can grow.
When the packing is finished, we can get the total size and write the packet header.

As a result, most packets can be built without making a single allocation, which results in a lot less garbage and a increased execution speed.