Unbuffered I/O Can Make Your Rust Programs Much Slower
- Use
straceandperfto count how many syscalls were invoked. - Yeah, Rust actually supports file I/O without buffer. It's may more simple in some situtations
Conclusion
In this post1, we saw that:
- System calls in Linux are slower than regular functions
- Issuing too many syscalls can have very negative effects on run-time performance
- By using
BufReaderandBufWriter, we can amortize the cost of syscalls- Even experienced programmers can miss these issues
- We can use
straceandawkto find if and where unbuffered I/O happens in our programs