back to blogs

optimizing compile times on gentoo

sysadmin // optimization09-01-26

compiling software from source is a ritual. wait times shouldn't be. getting emerge to fly requires a mix of modern linkers, hardware awareness, and aggressive caching.

// 1. the mold linker

the default gnu standard linker (ld) is slow.mold is a modern high-performance linker that can drastically cut down link times, especially for c++ heavy projects (looking at you, qt and llvm).

# /etc/portage/make.conf

LDFLAGS="${LDFLAGS} -fuse-ld=mold"

// 2. makeopts & load average

don't just set -j to your core count. consider your ram. if you have high core count but low ram, you will oom. a good rule of thumb is makeopts="-j$(nproc) -l$(nproc)" to keep the system responsive.

# /etc/portage/make.conf

MAKEOPTS="-j16 -l16"

// 3. ccache

if you recompile often (testing flags, updates), ccache is mandatory. it caches previous compilations so you don't start from zero.

# enable feature

FEATURES="ccache"

# set cache size (go big)

ccache -M 50G

// 4. use flags

disable what you don't need. bloated dependencies = longer compile times.-kde -gnome -systemd (if you dare) can shave off significant time by dropping heavy dependency trees.

conclusion: cpu go brrr, but smart config makes it go brrr faster.