4 ways to speed up your Github Action workflows

Jcdan
2 min readJun 6, 2021

--

In this post, we will go through 4 tips that could help you make your workflow run faster in Github Action.

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

That’s it for now. Make sure to check out my other post on how to run your Python script on Github action!

--

--

Jcdan
Jcdan

Written by Jcdan

Experience software developer in a quest to democratize software development. More here: https://www.linkedin.com/in/jcdansereau