Files
lighthouse/book/src/installation-source.md
Michael Sproul f77e3bc0ad Add maxperf build profile (#3608)
## Proposed Changes

Add a new Cargo compilation profile called `maxperf` which enables more aggressive compiler optimisations at the expense of compilation time.

Some rough initial benchmarks show that this can provide up to a 25% reduction to run time for CPU bound tasks like block processing: https://docs.google.com/spreadsheets/d/15jHuZe7lLHhZq9Nw8kc6EL0Qh_N_YAYqkW2NQ_Afmtk/edit

The numbers in that spreadsheet compare the `consensus-context` branch from #3604 to the same branch compiled with the `maxperf` profile using:

```
PROFILE=maxperf make install-lcli
```

## Additional Info

The downsides of the maxperf profile are:

- It increases compile times substantially, which will particularly impact low-spec hardware. Compiling `lcli` is about 3x slower. Compiling Lighthouse is about 5x slower on my 5950X: 17m 38s rather than 3m 28s.

As a result I think we should not enable this everywhere by default.

- **Option 1**: enable by default for our released binaries. This gives the majority of users the fastest version of `lighthouse` possible, at the expense of slowing down our release CI. Source builds will continue to use the default `release` profile unless users opt-in to `maxperf`.
- **Option 2**: enable by default for source builds. This gives users building from source an edge, but makes them pay for it with compilation time. 

I think I would prefer Option 1. I'll try doing some benchmarking to see how long a maxperf build of Lighthouse would take on GitHub actions.

Credit to Nicholas Nethercote for documenting these options in the Rust Performance Book: https://nnethercote.github.io/perf-book/build-configuration.html.
2022-09-29 06:13:33 +00:00

5.0 KiB

Build from Source

Lighthouse builds on Linux, macOS, and Windows. Install the Dependencies using the instructions below, and then proceed to Building Lighthouse.

Dependencies

First, install Rust using rustup. The rustup installer provides an easy way to update the Rust compiler, and works on all platforms.

With Rust installed, follow the instructions below to install dependencies relevant to your operating system.

Ubuntu

Install the following packages:

sudo apt install -y git gcc g++ make cmake pkg-config llvm-dev libclang-dev clang protobuf-compiler

Note: Lighthouse requires CMake v3.12 or newer, which isn't available in the package repositories of Ubuntu 18.04 or earlier. On these distributions CMake can still be installed via PPA: https://apt.kitware.com/

macOS

  1. Install the Homebrew package manager.
  2. Install CMake using Homebrew:
brew install cmake
  1. Install protoc using Homebrew:
brew install protobuf

Windows

  1. Install Git.
  2. Install the Chocolatey package manager for Windows.
  3. Install Make, CMake, LLVM and protoc using Chocolatey:
choco install make
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
choco install llvm
choco install protoc

These dependencies are for compiling Lighthouse natively on Windows. Lighthouse can also run successfully under the [Windows Subsystem for Linux (WSL)][WSL]. If using Ubuntu under WSL, you should follow the instructions for Ubuntu listed in the Dependencies (Ubuntu) section. [WSL]: https://docs.microsoft.com/en-us/windows/wsl/about

Build Lighthouse

Once you have Rust and the build dependencies you're ready to build Lighthouse:

git clone https://github.com/sigp/lighthouse.git
cd lighthouse
git checkout stable
make

Compilation may take around 10 minutes. Installation was successful if lighthouse --help displays the command-line documentation.

If you run into any issues, please check the Troubleshooting section, or reach out to us on Discord.

Update Lighthouse

You can update Lighthouse to a specific version by running the commands below. The lighthouse directory will be the location you cloned Lighthouse to during the installation process. ${VERSION} will be the version you wish to build in the format vX.X.X.

cd lighthouse
git fetch
git checkout ${VERSION}
make

Feature Flags

You can customise the features that Lighthouse is built with using the FEATURES environment variable. E.g.

FEATURES=gnosis,slasher-lmdb make

Commonly used features include:

  • gnosis: support for the Gnosis Beacon Chain.
  • portable: support for legacy hardware.
  • modern: support for exclusively modern hardware.
  • slasher-mdbx: support for the MDBX slasher backend (enabled by default).
  • slasher-lmdb: support for the LMDB slasher backend.

Compilation Profiles

You can customise the compiler settings used to compile Lighthouse via Cargo profiles.

Lighthouse includes several profiles which can be selected via the PROFILE environment variable.

  • release: default for source builds, enables most optimisations while not taking too long to compile.
  • maxperf: default for binary releases, enables aggressive optimisations including full LTO. Although compiling with this profile improves some benchmarks by around 20% compared to release, it imposes a significant cost at compile time and is only recommended if you have a fast CPU.

To compile with maxperf:

PROFILE=maxperf make

Troubleshooting

Command is not found

Lighthouse will be installed to CARGO_HOME or $HOME/.cargo. This directory needs to be on your PATH before you can run $ lighthouse.

See "Configuring the PATH environment variable" (rust-lang.org) for more information.

Compilation error

Make sure you are running the latest version of Rust. If you have installed Rust using rustup, simply type rustup update.

If you can't install the latest version of Rust you can instead compile using the Minimum Supported Rust Version (MSRV) which is listed under the rust-version key in Lighthouse's Cargo.toml.

If compilation fails with (signal: 9, SIGKILL: kill), this could mean your machine ran out of memory during compilation. If you are on a resource-constrained device you can look into cross compilation, or use a pre-built binary.

If compilation fails with error: linking with cc failed: exit code: 1, try running cargo clean.