Fix slow cargo builds by clearing the target directory and avoiding blanket hint-mostly-unused profiles.
Speed up cargo build by removing the target directory and ensuring you aren't misapplying the hint-mostly-unused profile globally.
rm -rf target
cargo build
If you have hint-mostly-unused = true set for package."*" in your Cargo.toml, remove it or scope it to specific heavy dependencies, as applying it globally slows down the build.
Your build is slow because Cargo is either re-compiling everything from scratch or you have a setting that tells it to optimize for unused code on every single dependency, which actually makes things slower. Deleting the build cache forces a clean start, and fixing the profile setting ensures Cargo only optimizes the right parts of your project.