I'm new to Rust and I'm trying to understand why can't Rust build faster. I'm specifically talking about the most common case, where I've made a small change in one of my source files and then I need to wait seconds for the cargo build
to do its job. Even if my app code is very small, if I add dependencies on MySQL and Rocket for example, those two crates will come with their own dependencies and apparently that's what makes the build process considerably slower. Obiously it is quite subjective what "slow" means, but if I need to wait 5-10 seconds for something I do a hundred times a day, I want to know why that needs to be the case and is there something I'm missing.
It seems to me that Cargo doesn't waste much time on the check whether it needs to re-compile any of those 200-300 (sub-)dependencies, but it is the linker that takes so long. And I'm trying to understand if there is an objective reason why the linker can't somehow optimize that process. Isn't it possible to somehow build and cache the whole MySQL and Rocket dependencies into two bigger libs, for example, and avoid doing all that work every single time? Even at the cost of some code duplication in the binary.
BTW I tried the LLD linker (I'm using Ubuntu) and it speeds things up to some degree, but it still seems to be heavily impacted by the big number of sub-dependencies.