Improve Rust Link Time with lld
Today I start to experiment with the WebGPU API, and I choose to use the wgpu-rs implementation in Rust. I am happy with the experience overall, but one difficulty I met is the long iterative compilation time:
The compile-time of my webgpu project is ridiculously slow (about 10s for this single file), any #Rust expert know how to improve that? https://t.co/SVZYs54L7E— Lesley Lai | Remember ThePhD (@LesleyLai6) November 2, 2020
For some applications, slow compile-time is OK. Coding some hard algorithms requires extensive thinking, and if they compile and pass unit tests, they are likely correct.
By contrast, for graphics and game programming, iteration time is paramount. A lot of the time, there are no right or wrong answer to a problem, instead, we need to do a lot of small tweakings.
Fortunately, a person (user Rukai) on the Graphics Programming Discord provides a solution.
What I need to do is to create a config file
[build] rustflags = [ "-C", "link-arg=-fuse-ld=lld", ]
This flag sets
lld to the linker, which is way faster than Rust's default linker.
And I also need to install
lld on my computer.
And this simple change magically makes my iterative compilation time under 3s. It is still not ideal from my perspective, but at least I can enjoy doing this project again.