Skip to content

Latest commit

 

History

History
114 lines (76 loc) · 3.69 KB

fast-compiles.md

File metadata and controls

114 lines (76 loc) · 3.69 KB

Fast compiles

This document attempts to capture the various lessons learned by Materialize engineers when optimizing machines for compiling Rust.

Run Linux

The most important step you can take to speed up Rust compilation times is to run Linux rather than macOS.

Your money goes much farther if you don't pay the Apple tax. For a given price point, you can usually build a Linux machine with twice as much compute, memory, and storage than a Mac.

A Linux machine will also allow you to run performance tests on your laptop. Our customer's production deployments are running on Linux, not macOS. While it's possible to get a rough sense of Materialize's performance on macOS, there have been more than a few occasions where apparent performance defects have disappeared when running the workload on Linux.

Use mold

On Linux using mold instead of the standard linker will result in an impressive linking speedup. On macOS make sure to have an up-to-date system with at least Xcode 15 to use the new system linker, which is similarly fast.

Installation

Linux

On Debian-based distros, you can install mold from the standard package repository:

sudo apt install mold

You'll need to hunt down the equivalent instructions for your distribution if you don't use a Debian-based distribution.

Configuration

To tell Rust to use mold, set the following environment variable:

export RUSTFLAGS="-C link-arg=-fuse-ld=mold"

Alternatively, you can configure the linker through a Cargo config file:

[build]
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

Disable debug info

The fastest known way to compile is with mold and disabling debug info:

export RUSTFLAGS="-C link-arg=-fuse-ld=mold -C debuginfo=0"

Ideally, set that in your ~/.bashrc or equivalent so that it applies permanently.

Example custom builds

The easiest way to speed up compilation is to throw some money at faster hardware. A few Materialize employees have embarked on this quest so far:

The jury is still out on whether more, slower cores (e.g., 3970x) is better than less, faster cores (e.g., 5950x) for the standard cargo build development cycle.

To date, no one has attempted to build a Linux laptop optimized for compilation performance.

Use a hosted machine

Hetzner provides reasonably-priced many-core AMD machines hosted Germany or Finland. While some may be using workstation rather than true server-grade hardware, they provide significantly faster compilation times than a standard laptop.

Community resources

Many folks in the Rust community have tips too. Some of those are collected here: