How we cut Lejar's CI from 55 minutes to about 10
Coding agents push changes to Lejar, our accounting product, all day. Every pull request waited about 55 minutes for its CI checks, which made CI the slowest part of shipping. On 1 November we changed the pipeline. A pull request now waits about 10 minutes, and each run costs about 60% less.
What we measured first
Across the last 25 merged pull requests, the median times for our CI jobs were:
- End-to-end tests: 55.3 minutes, on one machine.
- Unit job (type check, lint and unit tests, one after the other): 22.0 minutes.
- Build: 15.9 minutes.
- Integration tests: 7.4 minutes, already split across two machines.
The jobs run at the same time, so a pull request waits for the slowest one: the end-to-end job. The log of one 48-minute end-to-end run showed where its time went:
- Setup (install, browsers, a local database in Docker): about 3 minutes.
- First app build: about 1 minute.
- Second app build: about 26 minutes, of which 25.3 minutes was a TypeScript check.
- 704 smoke tests on a single worker: 18.2 minutes.
- The remaining test runs: under 2 minutes.
The second build wrote to a different output folder, so it found no cached type information and checked the whole project from zero. The same code was already type-checked elsewhere in the same pipeline.
What we changed
1. No type check inside CI builds. CI builds now skip the TypeScript check. Type checking runs once, in its own job. Production builds on Vercel still type-check, so nothing unchecked can ship. We made this change first. If we had split the tests across machines first, each machine would have paid for its own 25-minute check, and CI would have cost about 2.6 times more.
2. End-to-end tests on three machines. Each machine starts its own database in Docker, so the tests do not share data and there is no extra hosted database bill. Our test runner's default split would have put 657 of the 704 smoke tests on one machine, because one test group depends on all the others. We split them by hand into 244, 223 and 226 tests, and run the dependent group last on the third machine. The three machines finish in 7.3, 8.8 and 9.8 minutes.
3. TypeScript 7 for the type check. The type-check job now uses TypeScript 7, the native compiler. It takes 52 seconds from cold, against 955 seconds for TypeScript 5 on the same laptop, and about 1 second with a warm cache. We confirmed that it still catches errors by adding a file with deliberate type errors. TypeScript 5 stays installed for the tools that still need it.
4. Parallel jobs instead of one long job. Type check, lint and unit tests used to run one after the other in a 22-minute job. They are now three jobs that run side by side, in 1.5, 0.6 and 2.7 minutes.
5. No coverage collection. The unit tests no longer collect coverage, because no threshold used it.
6. A pre-push hook. Before each push, a git hook lints the changed files and type-checks the project, in about 3 seconds with a warm cache. Agents now find type errors on their own machine instead of after a CI run. We put this in a hook rather than in written instructions, because agents can skip a written step but cannot skip a hook.
Before and after
- Time a pull request waits: about 55 minutes before, about 10 minutes after.
- End-to-end tests: 55.3 minutes on one machine, now 7.3 to 9.8 minutes on three.
- Unit work: 22.0 minutes in one job, now three parallel jobs, the longest 2.7 minutes.
- Build: 15.9 minutes, now 0.4 minutes.
- Cost: about 60% less CI credit per run. A full run now costs about $0.46.
The largest single gain came from removing one duplicate type check. We found it by reading one log, step by step, before we changed anything.