rui314/mold

mold does not accelerate the compile process compare to normal config

Mon-ius opened this issue · 15 comments

DEV_ROOT=$HOME/.dev
DEV_DOWNLOAD=$DEV_ROOT/download
DEV_INSTALL=$DEV_ROOT/usr
PATH=$PATH:$DEV_ROOT/usr/bin

sudo apt-get install -y cmake gcc g++
git clone --depth 1 --branch stable https://github.com/rui314/mold.git

cmake -DCMAKE_INSTALL_PREFIX="$DEV_INSTALL" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=c++ -B build
cmake --build build -j$(nproc)
cmake --build build --target install --parallel "$(nproc)"

RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold -Z threads=32" cargo +nightly build --release
# vs
RUSTFLAGS="-Z threads=32" cargo +nightly build --release

And the result of readelf -p .comment $bin:

String dump of section '.comment':
  [     0]  rustc version 1.80.0-nightly (ada5e2c7b 2024-05-31)
  [    34]  GCC: (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
  [    5f]  mold 2.32.0 (ec04bfda9d01a18f4738f53d37756e99c648600d; compatible with GNU ld)
  [    af]  GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

If that's the case it is what it is. If linking is not the bottleneck of your build process, mold can't make it faster. Maybe your binary is relatively small?

I am aware if the process I have done for configure the mold is right, the linking part normally spent over 1min to process on Intel(R) Xeon(R) Platinum 8360Y CPU @ 2.40GHz in this case.

What is the overall wallclock time to build the entire source tree? What if you change a single file and rebuild it?

If change single file and rebuild it when RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold" cargo build --release, it spent 34.20s/1m 11s, 34.20s is for change a single file and rebuild it, 1m 11s is overall spend.

However, when pure perform cargo build --release without any FLAGs, it spent the similar, 34.66s/1m 45s.

When perform RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold -Z threads=32" cargo +nightly build --release, 34.63s/1m 42s

Each build test after cargo clean.

You don't want to run cargo clean after making a change to a file. Just change a single file and rebuild it, which is a typical scenario, and measure how much time does each build takes.

As mentioned, 34.20s, 34.66s and 34.63s are the time spent by change a single file and rebuild it. So, wired is, the three build process make no different

What if you do not change anything but just delete the generated executable and rebuild it?

@rui314 as you request,

  • 0.14s for standard cargo build --release
  • 0.14s for RUSTFLAGS="-Z threads=32" cargo +nightly build --release
  • 0.11s for RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold" cargo build --release
  • 0.11s for RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold -Z threads=32" cargo +nightly build --release

I'm not familiar with the rust build system, but aren't that the time the linkers take to link your program? If that's the case, the faster linker can't make any difference.

it takes about 0.03s faster in this case. One more question, does mold compatible with https://github.com/rust-lang/rustc_codegen_cranelift

Yes

Hi @rui314

Today, I tested a small program in Rust, which shows mold slow down about 60 ~ 200 percent compared to standard build.

3.96s, RUSTFLAGS="-Zcodegen-backend=cranelift -Z threads=8" cargo +nightly build --release,
6.19s, RUSTFLAGS="-Zcodegen-backend=cranelift -C linker=clang -C link-arg=-fuse-ld=mold -Z threads=8" cargo +nightly build --release
7.99s, RUSTFLAGS="-Zcodegen-backend=cranelift" cargo +nightly build --release,

11.52s, cargo +nightly build --release,
10.23s, RUSTFLAGS="-Z threads=8" cargo +nightly build --release,
14.66s, RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold -Z threads=8" cargo +nightly build --release,
18.94s, RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold" cargo +nightly build --release


19.95s, RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold" cargo build --release
18.11s, RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold -Z threads=8" cargo build --release

20.09s, cargo build --release
9.04s, RUSTFLAGS="-Z threads=8" cargo build --release

Instead of measuring only the total build time, can you measure how long does each internal step take?

do you mean cargo build --timings?

I'm afraid I don't know. I've never used cargo personally.