4 ways to speed up your Github Action workflows (2024)

1 - Parallelize with multiple jobs. You should analyze your current workflow to see if you can divide it into different jobs. Jobs as opposed to steps can be run in parallel by different machines (runners).

2 - Caching dependencies. Caching allows your workflow to store data for future uses, limiting the time spent downloading and making requests.

For instance, if you use a package manager like npm and on every run, you need to get the same dependency, you should cache it.

One way to do this is by using the actions/cache@v2 action.

A simple workflow caching step to cache Python requirement could look like this:

More info here https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows

3 -Select a faster runner. Currently, Github supports only a few virtual environments such as windows-2019 and ubuntu-20.04. If you don’t need windows specific libraries or dependencies, select Ubuntu since it’s will likely be faster (or at least test it).

If speed still is an issue, consider having a self-hosted runner high more CPU cores and memory.

4 -Use a strategy Matrix

The strategy matrix is a very interesting, yet powerful syntax in Github action. The matrix allows you to test many (up to 256) version configurations for the same job. These configs can be of a language, framework, OS, etc.

A simple example would be if you need to run your unit tests for your Python on Windows and Linux. And these tests, they need to pass on Python 3.6 and Python 3.9.

In this case, you would gain from using the strategy matrix, up to 4x faster!

Code-wise, it’s also a lot cleaner than repeating a job.

More info here: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix

4 ways to speed up your Github Action workflows (2024)
Top Articles
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 6289

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.