Recommended buffer size for the new IO?

Here are some rules of thumb:

  1. In a stream pipeline, buffers belong to edges not nodes. The node that connects the reader end of the pipeline to the writer end of the pipeline should be empty; the rest populated.
  2. In the middle of a stream pipeline, minimal buffer size that satisfies the constraints of each stream implementation is optimal. This requires reading documentation for the two stream implementations you are connecting and choosing the higher requirement.
  3. In the ends of a stream pipeline (file, network socket) ideal buffer size is sweet spot between evicting CPU cache lines and overcoming syscall overhead. This is typically 1K, 2K, or 4K, but can vary across operating systems, architectures, or application-specific details. I expect the difference between these three values to be fairly inconsequential.
9 Likes