GitLab CI basics - Time & Space Complexity
We want to understand how the time GitLab CI takes to run grows as the number of jobs or stages increases.
How does adding more jobs affect the total time GitLab CI spends executing pipelines?
Analyze the time complexity of this simple GitLab CI pipeline configuration.
stages:
- build
- test
build_job:
stage: build
script:
- echo "Building..."
test_job_1:
stage: test
script:
- echo "Testing part 1..."
test_job_2:
stage: test
script:
- echo "Testing part 2..."
This pipeline has two stages: build and test. The build stage has one job, and the test stage has two jobs running in parallel.
Look for repeated actions that affect total execution time.
- Primary operation: Running each job's script commands.
- How many times: Once per job, so total jobs count.
As you add more jobs, the total commands to run increase roughly by the number of jobs.
| Input Size (jobs) | Approx. Operations (job scripts run) |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The total work grows directly with the number of jobs.
Time Complexity: O(n)
This means the total time to run the pipeline grows linearly with the number of jobs if jobs run sequentially.
[X] Wrong: "Adding more jobs always makes the pipeline take that many times longer."
[OK] Correct: Jobs in the same stage run in parallel, so adding jobs in one stage may not increase total time as much as expected.
Understanding how pipeline time grows helps you design efficient CI workflows and explain your choices clearly in discussions.
"What if all jobs were in a single stage running sequentially? How would the time complexity change?"