# Benchmarks

Baseline numbers for the SQL-parse-mode graph builder. Generated by
`cargo bench --bench builder_bench`. Numbers below are from a single
machine (Linux, AMD64, Rust stable). Use them as relative references,
not absolute targets.

## Fixture

`benches/builder_bench.rs` generates a synthetic 500-model dbt project
into a temp directory on first invocation:

- 200 staging models, each ~6 lines of SQL with one source reference.
- 300 mart models, each ~8 lines of SQL with two ref calls (one via a
  detected wrapper macro to exercise #13).
- One `schema.yml` per layer with model descriptions.
- One macro file defining a simple `ref()` wrapper.

Total: 500 nodes, 500 `ref()` calls, 200 `source()` calls.

## Baseline (0.5.1)

| Target | Time | Notes |
|---|---|---|
| `build_graph_cold` (no cache) | **~17 ms** | Parses every file from scratch. Rayon parallelization across cores. |
| `build_graph_warm` (cache hit) | **~4.3 ms** | Cache populated by a prior cold run. Walks dirs + hashes files + serves cached parse. |
| `compute_summary` | **~114 µs** | Aggregation only — no I/O. |
| `compute_impact` | **~1.3 µs** | BFS from a deep-fan-in staging model. |

**Warm vs cold ratio: ~4×.** The warm path skips the lexer + regex
parsing entirely, just walks dirs and hashes file contents. The ratio
grows on real projects where model files are larger and parsing is
proportionally heavier.

### Lexer overhead (#25)

Cold parse went from ~14.4ms (0.5.0, regex-only) to ~17ms (0.5.1, with
Jinja+SQL lexer in the path). The ~15% extra buys correctness — false
positives from `ref(` inside string literals and comments are now
eliminated. Worth it.

## Reading the numbers

For context: 14.4 ms cold means a 500-model project rebuilds the full
graph in well under a frame on a developer laptop. 5.2 ms warm is
sub-frame, effectively instant. The cache earns its keep most on
projects where:

- Models are large (heavy Jinja, many lines of SQL).
- The user runs `dbt-lineage` repeatedly (TUI dev loop, CI watch).

## Regression policy

When changes to the parser, builder, or cache affect these numbers,
update this file in the same commit. CI doesn't gate on bench
performance yet — these are reference numbers for humans.
