r/reactjs • • 11h ago

Resource We recently cut down our React GitLab CI pipeline from ~15 min to 6 min using memoization and I have some thoughts to share

We are a three-person team where tech lead is more focused on management than technical work, so we often end up reinventing the wheel due to gaps in our knowledge. Recently, we realized we were waiting 15 minutes for an image to build on every push and usually we have to make two to three commits to get all pipeline stages passing (AI not doing its job properly and test coverage falls short.)

That's when I looked more into our React repo’s GitLab CI pipeline. The historical median was 14m 48s (p90 24m 51s). Earlier runner and test-suite updates had already brought runs down to about 9 minutes. After applying memoization across our jobs, the median was 6m 19s, with a best run of 5m 07s.

Here are the changes we made:

  • Decoupled install from test:unit and enabled the shared S3 npm cache keyed by package-lock.json. Install dropped from ~110s to 45–54s.
  • Skipped lint, typecheck, and test:a11y on pushes that don’t touch app code using rules:changes and optional: true in downstream needs.
  • Gave test:unit two modes. It runs the suite when test inputs change. On no-code pushes it fetches prior test and coverage artifacts via CI_JOB_TOKEN so our policy gates still pass. Reuse took 17–18s versus 2m 20s for a full run. We also replaced grep | head -1 with a single awk command after SIGPIPE caused an exit 141 under pipefail.
  • Moved Kaniko’s --cache-repo to the GitLab Container Registry after ECR returned a 403 for cache-layer uploads. The final image still goes to ECR. The build took 2m 20s cold and 36s warm on an unchanged-source push.

While none of this is groundbreaking, I got to implement it for our team and cut a real daily bottleneck—and I feel good about it.

https://medium.com/@veldt/how-i-cut-my-gitlab-ci-pipeline-from-18-minutes-to-5-minutes-using-memoization-cd743108702d

Personal Blog

18 Upvotes

4 comments sorted by

1

u/otheyhigh 6h ago

Nice read! Had a few thoughts and was curious what people think.

— I would phrase it “I want to run my tests whenever I am building a new instance of the application”. This can sometimes help with isolating non-app changes as their own deployments (vs deploying the whole system)
— Would zero install solutions like pnpm be a good choice to help save more time?

1

u/Darex97 4h ago

How do you decide what counts as a test input?

Nice btw!

1

u/shadohunter3321 2h ago

Why not move the testing to PR level? Keeps the release branch always buildable. Someone else won't need to wait for others to fix their issues before they can deploy their change. Also, the CI time gets split into 2 different pipelines.