Post

Speeding up GitLab Dependency Caching

santerre.xyz / 2024

The problem

Anyone who has worked in JavaScript long enough has seen dependency folders get large. In a monorepo with many packages, install time can become one of the slowest parts of CI/CD.

The usual answer

GitLab's built-in caching is the obvious first pass: point the cache at your dependency folder and let future builds restore it. That works until the cache itself becomes expensive to compress and extract.

The practical fix

For large dependency trees, tar-based archives can be materially faster than zip-based cache behavior. The win is not only download time; it is also the time spent moving many small files into place.

In one large monorepo, switching the cache archive approach reduced cache push time from roughly one minute to about ten seconds, and restore time from roughly ninety seconds to about ten seconds.