- Rust compiles in debug mode by default. It results in faster compilations, but does next to no optimizations, and slows down the code.
- It uses unbuffered File IO. So, when you write files, wrap them in a BufWriter/BufReader.
- Read::lines() iterator is easy to use, but it allocates a String for each line. Manually allocate and reuse a String to reduce memory churn to gain a bit of performance.
- In simple cases, use an iterator instead of an index loop.
- Avoid needles collect() and allocations.
Full post here, 7 mins read