r/reactjs • u/Forsaken_Put_3794 • 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
installfromtest:unitand enabled the shared S3 npm cache keyed bypackage-lock.json. Install dropped from ~110s to 45–54s. - Skipped
lint,typecheck, andtest:a11yon pushes that don’t touch app code usingrules:changesandoptional: truein downstreamneeds. - Gave
test:unittwo modes. It runs the suite when test inputs change. On no-code pushes it fetches prior test and coverage artifacts viaCI_JOB_TOKENso our policy gates still pass. Reuse took 17–18s versus 2m 20s for a full run. We also replacedgrep | head -1with a singleawkcommand afterSIGPIPEcaused an exit 141 underpipefail. - Moved Kaniko’s
--cache-repoto 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.
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.