r/reactjs • • 1d 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

26 Upvotes

14 comments sorted by

12

u/shadohunter3321 21h 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.

1

u/Forsaken_Put_3794 12h ago

We do have separate pipelines for merge requests, but we also have some organization-enforced policies that run after the ci pipeline. Some of these policies depend on artifacts generated during the testing stage, such as test_coverage.xml. So until all the polices are also green, raising a MR is blocked.

3

u/otheyhigh 1d 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/Forsaken_Put_3794 12h ago

Yeah, I agree using pnpm could save me some more time. It hadn’t occurred to me, so I’ll give it a try today. Thanks for the feedback!

On the testing point, I’ll just copy paste my reply:

We do have separate pipelines for merge requests, but we also have some organization-enforced policies that run after the ci pipeline. Some of these policies depend on artifacts generated during the testing stage, such as test_coverage.xml. So until all the polices are also green, raising a MR is blocked.

1

u/otheyhigh 11h ago

That makes sense. Guess maybe where I leading towards is how can configuration changes be decoupled from the service code. Could be a separate repo or a data store. But that would then require its own service to expose interfaces to access config. At that point, it most probably is over engineering things.

The hiccup I was exploring is the possibility of differences in the dependencies resourced. Although version changes would be limited to at most minor or patch, both the instances might not be exact copies.

But this is such an extreme scenario that exploring other options might just not be worth the effort.

One thing I thought was around maybe using multiple test suites. A comprehensive suite that would need to run at push. A complete suite which focuses on happy path use cases in the system functionality. Some unhappy as well but not all possibilities.

1

u/QuietlyFeigned 14h ago

pnpm with a cached store saves huge time Yarn Berry is great if you want true zero installs

1

u/otheyhigh 12h ago

I use yarn berry but Vite was having issues so had to stick with node_modules

1

u/yuussef11 16h ago

Its you or claude ?

0

u/Forsaken_Put_3794 12h ago

Both, most of the data you see here is pulled by the claude via gitlab mcp and the steps written in the article under step-by-step implementation section are also written by claude since the implementation was done by it. Rest is all me.

1

u/Prozilla6 3h ago

So what did you do?

2

u/Money-Lynx-2333 7h ago

shit you guys live like this?

1

u/Darex97 23h ago

How do you decide what counts as a test input?

Nice btw!

•

u/Fast_Information3546 25m ago

Cutting build times from ~15m down to 6m is huge—especially when waiting on pipelines slows down iteration. Where did you see the biggest win from memoization across the pipeline steps?