Unbuffered I/O Can Make Your Rust Programs Much Slower
Date: 1/7/2022 · Tags: #rust, #til, #python, #dev- Use
strace
andperf
to 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
BufReader
andBufWriter
, we can amortize the cost of syscalls- Even experienced programmers can miss these issues
- We can use
strace
andawk
to find if and where unbuffered I/O happens in our programs