Difference between revisions of "Makepkg-optimize"

From ArchWiki
Jump to: navigation, search
m (Build an optimized package in a clean chroot: reduce superfluous linking; reset pgo cache permissions to 777 (both user and root may write profiles); abbreviate PGO)
m (Building with PGO: specify 'program' exit(); minor formatting.)
 
Line 79: Line 79:
 
Once the package is [[Pacman#Additional commands|installed]], test-run its executables.
 
Once the package is [[Pacman#Additional commands|installed]], test-run its executables.
  
{{Note|Profiles are generated on {{ic|exit()}}. Persistent daemons, such as [[systemd]], may require a reboot to produce profiles; if you have rebooted, be sure to rebind the PGO cache before rebuilding.}}
+
{{Note|Profiles are generated on program {{ic|exit()}}. Persistent daemons, such as [[systemd]], may require a reboot to produce profiles. If you have rebooted, be sure to rebind the PGO cache before rebuilding.}}
  
 
For the second building phase, do ''not'' pass {{ic|-c}} to {{ic|makechrootpkg}}, but clean {{ic|$srcdir}} and overwrite the previous package by passing {{ic|-Cf}} to {{ic|makepkg}}:
 
For the second building phase, do ''not'' pass {{ic|-c}} to {{ic|makechrootpkg}}, but clean {{ic|$srcdir}} and overwrite the previous package by passing {{ic|-Cf}} to {{ic|makepkg}}:
  
 
  $ makechrootpkg -r "$CHROOT" -- -Cf --config /etc/makepkg-optimize.conf
 
  $ makechrootpkg -r "$CHROOT" -- -Cf --config /etc/makepkg-optimize.conf

Latest revision as of 15:00, 4 December 2018

makepkg-optimizeAUR is a collection of supplemental buildenv and tidy scripts for pacman-gitAUR which provide macros for several kinds of optimization in the build() and package() stages.

Installation

Install makepkg-optimizeAUR from the AUR and, to make optimizations available, install their backends: openmp, upx, optipng, and nodejs-svgoAUR

Configuration

makepkg-optimizeAUR generates a redundant configuration file, /etc/makepkg-optimize.conf, from your current makepkg configuration.

This file lists the supplementary options for COMPILE FLAGS, BUILD ENVIRONMENT, GLOBAL PACKAGE OPTIONS, PACKAGE OUTPUT, and COMPRESSION DEFAULTS, all of which are disabled by default.

Warning: Some packages may fail to build with certain optimizations and over-optimization may cause problems for some programs--such as decreased performance and segmentation faults.

Build an optimized package

After selecting your preferred optimizations, pass the configuration file when building:

$ makepkg --config /etc/makepkg-optimize.conf
Note: Profile-guided optimization requires that a package be built and installed twice. The first phase initiates profile generation in $PROFDEST/$pkgbase.gen; the second moves them to $PROFDEST/$pkgbase.used and applies them.

Build an optimized package in a clean chroot

Alternatively, makepkg-optimize can be used to build optimized packages within a chroot.

Chroot setup

After setting up a chroot, a few additional steps are needed.

Install makepkg-optimize and backends

First, install some of the backends for the optimization macros to the base chroot:

$ arch-nspawn "$CHROOT"/root pacman -S openmp upx optipng

Then download and build makepkg-optimizeAUR and nodejs-svgoAUR.

To install them in the base chroot, copy their package files into it and install them, e.g.:

# cp nodejs-svgo-1.1.1-1-any.pkg.tar.xz "$CHROOT"/root/root/
$ arch-nspawn "$CHROOT"/root pacman -U /root/nodejs-svgo-1.1.1-1-any.pkg.tar.xz

Create a PGO cache

To use PGO, create a folder in the same place, inside and outside of the chroot, to store profiles:

# mkdir -m 777 {"$CHROOT"/root,}/mnt/pgo

Then edit $CHROOT/root/etc/makepkg-optimize.conf and set PROFDEST=/mnt/pgo.

Using the chroot

Note: When updating the chroot, AUR packages have to be updated manually.

Build a package

First, edit $CHROOT/root/etc/makepkg-optimize.conf and select your preferred optimizations.

When building, pass the configuration file to makepkg:

$ makechrootpkg -c -r "$CHROOT" -- --config /etc/makepkg-optimize.conf
Building with PGO

After the first building phase, bind the PGO cache:

# mount -o bind {,"$CHROOT"/"$USER"}/mnt/pgo
Tip: Alternatively, use fstab to bind these folders persistently.

Once the package is installed, test-run its executables.

Note: Profiles are generated on program exit(). Persistent daemons, such as systemd, may require a reboot to produce profiles. If you have rebooted, be sure to rebind the PGO cache before rebuilding.

For the second building phase, do not pass -c to makechrootpkg, but clean $srcdir and overwrite the previous package by passing -Cf to makepkg:

$ makechrootpkg -r "$CHROOT" -- -Cf --config /etc/makepkg-optimize.conf