Skip to content
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

Switch from ld (the default linker) to using lld for GNU Linux targets #8166

Merged
merged 2 commits into from
May 17, 2024

Conversation

bgw
Copy link
Member

@bgw bgw commented May 17, 2024

What's wrong with ld? It's very slow and uses a lot of memory.

Why lld? It's fast, mature, and well-supported. Meta and Google use it for all their linking workloads. We're already using it for macos and x86-64 Windows. There is ongoing work to make it the default for rustc, and it already is default on a few platforms.

Why not mold? Mold is generally faster, but the margin is slim enough for our workloads that it doesn't really matter. Mold only recently got support for LTO, doesn't support v0 rust symbol demanging, doesn't support BOLT (though we don't use that yet), etc. Mold is maturing quickly, but lld still seems like the "safer" choice.

Benchmark Caveats

This is using https://github.com/bgw/benchmark-scripts. That machine has a bunch of CPU cores disabled, so the benchmark is running on 4 cores without SMT. With higher core/thread counts, mold will almost certainly perform better as it's heavily multi-threaded. However, I think these benchmarks do enough to show that the real enemy is ld, and lld is close enough to mold.

Turbopack Warm Build

Modify a string in an error message inside of crates/turbopack-ecmascript/src/minify.rs. This guarantees forced recompilation of all dependent crates without meaninfully changing any behavior. Then run:

time RUSTFLAGS=... cargo build -p turbopack-cli

With GNU ld (2.40)

Without RUSTFLAGS

real    1m24.296s

With Mold (1.10.1, Debian 12)

Using RUSTFLAGS=-Clink-arg=-fuse-ld=mold

real    0m38.189s

With LLD (14.0.6, Debian 12)

Using RUSTFLAGS=-Clink-arg=-fuse-ld=lld

real    0m39.810s

Turbopack Cold Build

rm -rf target/ && time RUSTFLAGS=... cargo build -p turbopack-cli

With GNU ld (2.40)

Without RUSTFLAGS

real    11m24.960s

With Mold (1.10.1, Debian 12)

Using RUSTFLAGS=-Clink-arg=-fuse-ld=mold

real    10m14.209s

With LLD (14.0.6, Debian 12)

Using RUSTFLAGS=-Clink-arg=-fuse-ld=lld

real    10m15.404s

Turborepo Cold Build

rm -rf target/ && time RUSTFLAGS=... cargo build -p turbo

With GNU ld (2.40)

Without RUSTFLAGS

real    5m22.796s

With Mold (1.10.1, Debian 12)

Using RUSTFLAGS=-Clink-arg=-fuse-ld=mold

real    4m53.936s

With LLD (14.0.6, Debian 12)

Using RUSTFLAGS=-Clink-arg=-fuse-ld=lld

real    4m54.182s

Tests Cold Build

This produces a large number of binary targets in parallel.

rm -rf target/ && time RUSTFLAGS=-Clink-arg=-fuse-ld=mold cargo nextest run -- dummy_filter_build_only_dont_run_any_tests

With GNU ld (2.40)

Without RUSTFLAGS

No numbers, as this OOMs (!!!) (16GB of RAM)

With Mold (1.10.1, Debian 12)

Using RUSTFLAGS=-Clink-arg=-fuse-ld=mold

real    15m29.912s

With LLD (14.0.6, Debian 12)

Using RUSTFLAGS=-Clink-arg=-fuse-ld=lld

real    15m19.553s

**What's wrong with `ld`?** It's very slow and uses a lot of memory.

**Why `lld`?** It's fast, mature, and well-supported. Meta and Google use it for all their linking workloads. We're already using it for macos and x86-64 Windows. There is [ongoing work to make it the default for rustc](rust-lang/rust#71515), and it already is default on a few platforms.

**Why not `mold`?** Mold is generally faster, but the margin is slim enough for our workloads that it doesn't really matter. Mold only recently got support for LTO, doesn't support v0 rust symbol demanging, doesn't support BOLT (though we don't use that yet), etc. Mold is maturing quickly, but `lld` still seems like the "safer" choice.
Copy link

vercel bot commented May 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2024 3:42am
9 Ignored Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 3:42am
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 3:42am
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 3:42am
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 3:42am
examples-native-web ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 3:42am
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 3:42am
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 3:42am
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 3:42am
rust-docs ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 3:42am

Copy link
Member Author

bgw commented May 17, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @bgw and the rest of your teammates on Graphite Graphite

@bgw bgw requested review from a team, tknickman and chris-olszewski and removed request for a team May 17, 2024 03:19
@bgw bgw marked this pull request as ready for review May 17, 2024 03:20
@bgw bgw requested a review from a team as a code owner May 17, 2024 03:20
Copy link
Contributor

github-actions bot commented May 17, 2024

🟢 Turbopack Benchmark CI successful 🟢

Thanks

Copy link
Contributor

✅ This change can build next-swc

Copy link
Contributor

github-actions bot commented May 17, 2024

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Turbopack Rust tests (mac/win, non-blocking)

See workflow summary for details

@bgw bgw merged commit 1299d8d into main May 17, 2024
59 of 61 checks passed
@bgw bgw deleted the bgw/lld-linker branch May 17, 2024 16:20
bgw added a commit to vercel/next.js that referenced this pull request May 17, 2024
bgw added a commit to vercel/next.js that referenced this pull request May 17, 2024
Neosoulink pushed a commit to Neosoulink/turbo that referenced this pull request Jun 14, 2024
vercel#8166)

**What's wrong with `ld`?** It's very slow and uses a lot of memory.

**Why `lld`?** It's fast, mature, and well-supported. Meta and Google
use it for all their linking workloads. We're already using it for macos
and x86-64 Windows. There is [ongoing work to make it the default for
rustc](rust-lang/rust#71515), and it already
is default on a few platforms.

**Why not `mold`?** Mold is generally faster, but the margin is slim
enough for our workloads that it doesn't really matter. Mold only
recently got support for LTO, doesn't support v0 rust symbol demanging,
doesn't support BOLT (though we don't use that yet), etc. Mold is
maturing quickly, but `lld` still seems like the "safer" choice.
bgw added a commit to vercel/next.js that referenced this pull request Jul 3, 2024
bgw added a commit to vercel/next.js that referenced this pull request Aug 4, 2024
mischnic pushed a commit to vercel/next.js that referenced this pull request Aug 5, 2024
bgw added a commit to vercel/next.js that referenced this pull request Aug 5, 2024
bgw added a commit to vercel/next.js that referenced this pull request Aug 6, 2024
#65898)

Copies changes from vercel/turborepo#8166, and
updates contributing documentation to include the installation of lld.

> **What's wrong with `ld`?** It's very slow and uses a lot of memory.
>
> **Why `lld`?** It's fast, mature, and well-supported. Meta and Google
use it for all their linking workloads. We're already using it for macos
and x86-64 Windows. There is [ongoing work to make it the default for
rustc](rust-lang/rust#71515), and it already
is default on a few platforms.
>
> **Why not `mold`?** Mold is generally faster, but the margin is slim
enough for our workloads that it doesn't really matter. Mold only
recently got support for LTO, doesn't support v0 rust symbol demanging,
doesn't support BOLT (though we don't use that yet), etc. Mold is
maturing quickly, but `lld` still seems like the "safer" choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants