Minimizing compilation and installation time

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

Most packages will install very quickly on reasonably fast modern hardware, but there are heavier packages, and a few very large ones. Here are some tips to minimize compilation and installation times on Gentoo.

Note that not all packages are compiled, in the usual sense: many are written in interpreted langues such as Python and do not always use a heavy build process. Some packages are installed directly in a precompiled "binary" format.

Tip
When installing software, use the --ask --verbose (-av) options and inspect the dependencies that would be pulled in for any large packages that could be replaced by a -bin version, or may even not be needed at all.

Avoid unneeded packages

Installing software often pulls in dependencies, and some of these dependencies may be large packages. Inspect what will be installed when emerging, and adjust USE flags to avoid any unneeded dependencies, if possible.

QtWebEngine

QtWebEngine is a particularly large package that takes a long time to compile. Some packages will pull it in as a dependency by default, but this is not always required or desired.

To avoid having to compile dev-qt/qtwebengine as a dependency for certain packages, add -webengine to make.conf:

FILE /etc/portage/make.conf
USE="pulseaudio -webengine -bluetooth bash-completion"

For some packages, the gui, urlpreview, rss, qt5, pyqt5, dictionary-manager and maybe other USE flags determine QtWebEngine dependency, so it may be useful to watch if theses flags are needed for certain packages or not.

If QtWebEngine has already been pulled in as a dependency, and may now be removed, execute the following commands after modifying make.conf:

root #emaint sync --auto
root #emerge --ask --verbose --update --deep --newuse @world
root #emerge --ask --depclean

Some packages depend unconditionally on QtWebEngine. If these packages are not needed, simply avoid installing them!

Tip
For anyone wanting to be absolutely certain to avoid emerging QtWebEngine, consider adding it to /etc/portage/package.mask.

Configure portage to optimize build times

Portage should be configured to use resources in a reasonable manner, in order to achieve the best possible build times. Generally things will be set up to use all processing threads available, memory capacity permitting.

Portage niceness may be set to allow using the system while Portage is merging packages, while minimally impacting build time.

The main variables to pay attention to are EMERGE_DEFAULT_OPTS and MAKEOPTS.

See Portage niceness to set up Portage to let other processes be given priority, to allow full use of the system while installing or updating packages.

Select compiler options for compilation speed

Some CFLAGS such as -pgo will result in much longer compile times. The pgo USE flag has the same effect.

Alternative binary packages ("-bin" packages)

Some packages have a precompiled alternative, provided by the Gentoo developers. These allow fast installation of packages that otherwise take a particularly long time to compile. Note that the "-bin" packages referred to here are precompiled versions of packages available in the Ebuild repository - there are also binary packages in the repository for other reasons, such as for software that is only available in binary form.

The devs pay great attention to building these versions, there is usually no noticeable performance hit to using them, though usually any difference one way or the other is negligible.

For packages that have USE flags, the "-bin" versions use common defaults. If it is required to change the USE flags for a package, a "-bin" version may not be appropriate, though it is uncommon to have to do so.

Tip
These packages are particularly expensive to compile:

Substituting a source based dependency for "-bin" version

When installing a package would pull in a large package that would advantageously be replaced by it's "-bin" version, it is possible to substitute the former for the latter.

When noticing a large packing being pulled in as a dependency, first abort the merge before starting. Then emerge the "-bin" version without adding it to the world file:

root #emerge --oneshot <category>/<package>-bin

Because dependencies on packages that have a "-bin" version are virtual, simply emerge the original package, and the "-bin" version will be used as the dependency.

Make binary packages on a secondary machine

If another, maybe more powerful, machine is available, it could be set up to build binary packages to be used on the first machine with a binhost. Packages built this way may be shared among several machines, if they share the same architecture and use similar USE flags.

Hardware

Of course, more powerful hardware will allow faster compilation times, though it will usually also be the most cumbersome and expensive way to make things faster. Some upgrades may be reasonable though, such as adding RAM on a memory limited machine (it's generally advised to have two GB per processor thread). Some systems have cheaper memory sticks available to them than others however.

An SSD, particularly an NVMe SSD, can sometimes be a reasonably cheap way to make installation faster, if coming from a traditional spinning hard drive.

Put Portage TMPDIR on tmpfs

It is possible to have Portage build packages in RAM with tmpfs instead of using a Hard Disk Drive (HDD) or Solid State Drive (SSD). This can sometimes speed up emerge times, for those who have enough RAM. See the Portage TMPDIR on tmpfs article.

Tips

--newuse vs --changed-use

The --changed-use parameter may be used to do less rebuilds while updating. Using the --newuse parameter however will let installed packages better reflect the state of the current Gentoo ebuild repository.

See also

  • ccache — helps avoid repeated recompilation for the same C and C++ object files by fetching result from a cache directory.
  • distcc — a program designed to distribute compiling tasks across a network to participating hosts.
  • genlop — a utility for extracting information about emerged ebuilds from Portage log files - show build times
  • Portage with Git — use Git to synchronize the Gentoo ebuild repository
  • qlop - q applets are fast Portage query utilities written in C, show build times with qlop