Skip to content

config to switch linker to mold for linux target #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 14, 2022
Merged

Conversation

pretentious7
Copy link
Contributor

PROBLEM:
dev hot-rebuilds currently take ~10s on a 4c8t intel laptop
from circa 2017. (rustc 1.61.0)

SOLUTION:
After switching to mold, this time drops to ~3.5s.

FURTHER INFORMATION:
Profiling via rustc --self-profile reveals that most of the time
for a hot reload comes from linking. mold is a faster linker than
lld or ld.

POSSIBLE IMPROVEMENTS:
Switching to rust nightly (currently 1.63.0) yield further 20-30%
improvements.

PROBLEM:
dev hot-rebuilds currently take ~10s on a 4c8t intel laptop
from circa 2017. (rustc 1.61.0)

SOLUTION:
After switching to mold, this time drops to ~3.5s.

FURTHER INFORMATION:
Profiling via rustc --self-profile reveals that most of the time
for a hot reload comes from linking. mold is a faster linker than
lld or ld.

POSSIBLE IMPROVEMENTS:
Switching to rust nightly (currently 1.63.0) yield further 20-30%
improvements.
PROBLEM: unit tests and integration tests error out because
	mold not installed on gh actions machines

SOLUTION: Use Rui Ueyama's first party github action
	https://github.com/rui314/setup-mold
PROBLEM:
Ueyama's gh action installs mold to /usr/local/bin/mold
whereas cargo configured to look for it at /usr/bin/mold

SOLUTION: change cargo path to /usr/local/bin/mold

POSSIBLE IMPROVEMENTS:
I really wish it was possible to have the config file include
macros somehow. (so something like /usr/bin/env mold, or which
mold), but that doesn't seem feasible without having a config
generator which seems excessive for just this, but might be
good if there's more dynamic configuration in the future.
@@ -0,0 +1,3 @@
[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-C", "link-arg=--ld-path=/usr/local/bin/mold"]
Copy link
Member

@paulgb paulgb Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be:

rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, it's deprecated, but is fine for now. esp considering stuff like this
rust-lang/rust#94347

PROBLEM: gh-actions clang is old and does not support --ld-path

SOLUTION: switch to deprecated -fuse-ld

NOTES:
I suspect that the rust project will switch to mold as default
linker for linux before we have to worry about changing this
path anyhow.
@pretentious7
Copy link
Contributor Author

OK that should be good. In the future, or if we decide to switch to nightly, something like this might be worthwhile: https://github.com/dimensionhq/fleet

@pretentious7 pretentious7 merged commit 860547f into main Jun 14, 2022
pretentious7 added a commit that referenced this pull request Jun 15, 2022
This reverts commit 860547f.

PROBLEM: messes up docker push
SOLUTION: remove linker switch

NOTE:
issues mentioned in 86054 still apply, and will be addressed
in this PR.
pretentious7 added a commit that referenced this pull request Jun 15, 2022
* Revert "config to switch linker to mold for linux target (#51)"

This reverts commit 860547f.

PROBLEM: messes up docker push
SOLUTION: remove linker switch

NOTE:
issues mentioned in 86054 still apply, and will be addressed
in this PR.

* add fast_build script that runs cargo build with the mold linker

PROBLEM:
as mentioned in 86054, hot-reloads take around 10s, mostly due to
linker.

SOLUTION:
use mold, this time via a fast_build script that sets the necessary
cargo env vars, ensures that mold and clang are installed, and runs
cargo build with the correct path for the mold linker.

POSSIBLE IMPROVEMENTS:
may be a good idea to switch the shell script for a zx script. Also
would be nice if `cargo build` automatically ran fast_build.sh as a
wrapper if the host and profile are correct (ie. linux host, with
dev profile)

* CLEANUP: remove .cargo from dockerignore

Co-authored-by: Abhishek Cherath <[email protected]>
@rolyatmax rolyatmax deleted the speed-up-build branch June 27, 2022 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants