The default buffer size is 8k in BufferedWriter
of somewhere else. Why use 8k? Does larger buffer size improve the performance?
Why default buffer size is 8k in Java IO?
Asked Answered
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.
© 2022 - 2024 — McMap. All rights reserved.