Introduction
According to this blog post, a new option for getting crates has been introduced in Rust 1.68, which can considerable shorten compile times.
Maybe it is time to put it to the test. I have an existing project from this post which uses a lots of crates to experiment with, which seems like a good testbed. First let’s try it without the sparse protocol:
As you can see, it takes almost two minutes to compile.
Now it’s time to switch on the sparse protocol:
What you do is:
- If it doesn’t exist, create a .cargo directory in the root of your project
- Add a config.toml in the newly created directory.
Then add the following code to the config.toml file:
[registries.crates-io]
protocol = "sparse"
After typing
cargo clean
I tried building it again, and lo and behold:
More than 22 seconds shorter.
Conclusion
This new features looks promising. Rust is a great language, but compiletimes can indeed be a problem, and this is a step in the right direction. I hope the Rust team can further optimize this.