Slim CI with state comparison in dbt - Time & Space Complexity
When using Slim CI with state comparison in dbt, we want to know how the time to run changes as the project grows.
We ask: How does comparing states affect the work dbt does during a run?
Analyze the time complexity of the following dbt slim CI snippet.
-- slim CI with state comparison
-- run only models changed since last run
{
"state": {
"revision": "abc123",
"compare": true
}
}
-- dbt runs only changed models and their dependencies
This snippet tells dbt to compare the current project state with a saved state and run only changed models.
Look for repeated checks or traversals.
- Primary operation: Traversing the dependency graph to find changed models.
- How many times: Once per run, checking each model's state.
As the number of models grows, dbt checks each model once to see if it changed.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 state checks |
| 100 | About 100 state checks |
| 1000 | About 1000 state checks |
Pattern observation: The work grows directly with the number of models.
Time Complexity: O(n)
This means the time to compare states and run changed models grows linearly with the number of models.
[X] Wrong: "Slim CI runs only a few models, so it always takes constant time."
[OK] Correct: Even if only a few models run, dbt still checks all models to find changes, so time grows with project size.
Understanding how state comparison scales helps you explain efficient CI runs and smart build processes in real projects.
"What if dbt cached the state comparison results? How would that change the time complexity?"