9

The default buffer size is 8k in BufferedWriter of somewhere else. Why use 8k? Does larger buffer size improve the performance?

Hesey
  • 4,957
  • 6
  • 31
  • 31

1 Answers1

6

The buffer reduces the number of write system calls and thereby optimizes the output. Depending on your program's activity a bigger write buffer may improve performance, it's always best to test with a bigger buffer with a workload comparable to what your program does. Also, the buffer's importance is higher when the underlying filesystem's cache is write-through (no write cache), because a write-behind cache will delay/group the physical write operations anyways.

I think the historical reason for the 8k is related to the traditional allocation sizes on disk, often 2k or a multiple thereof.

fvu
  • 32,488
  • 6
  • 61
  • 79