A few simple tricks to tune your github actions runtime

Github actions are a nice thing, spin up your preferred operating system and execute some tests. While implementing them in one of my projects, i had to trial and error and: waiting for the tests to complete is an annoying situation!

Using the ubuntu-latest image and installing several software components, two lines catched my eyes while waiting for the packages to install:

Processing triggers for man-db (2.9.4-2) ...
Processing triggers for initramfs-tools (0.140) ...

The reason for these log messages is quite simple. If you install any package on ubuntu-latest, it detects added manpages and altered system settings that need to be applied to the systems initramfs.

Re-computing the initramfs is a quite cpu and storage intensive operation and it comes with some real time penalty! Updating the manpages database too.

So why do it if you spin up just a throwaway machine? Lets disable these triggers with two simple commands in your github workflow:

- name: Disable initramfs update
  run: sudo sed -i 's/yes/no/g' /etc/initramfs-tools/update-initramfs.conf
- name: Disable man-db update
  run: sudo rm -f /var/lib/man-db/auto-update

and save some time! Look at the durations of this example repository:

Example repository actions

The Tuned workflow script in this repository disables various trigger actions, such as man-db, initramfs, mime and others.

During package installation, dpkg attempts to call the filesystem sync() operation to ensure save I/O operations. This can also be disabled by enabling the force-unsafe-io option in etc/dpkg/dpkg.cfg.d/.

Using all these simple tricks saves up to ~40 seconds in this example, depending on how many packages you install (for man-db) and if you install different packages in multiple stages, you might save even more time.

You can include this action into your projects yml files with the github action using flag, see this example repository

Have a look at the general Dpkg-Triggers documentation, there are more time savers to disable ..

Another option is to use the github caching workflow for other dependencies you install via third party package managers (npm, etc) to speedup your runtime (Note: This makes sense with small components, not big package dependencies, as you might easily exceed the maximum allowed cache size of 5 GB.)

Written on August 18, 2021