baml_language/crates/baml_tests/BENCHMARKS.md
This directory contains comprehensive benchmarks for the BAML compiler, measuring performance across different scenarios.
# Run all benchmarks
cargo bench --bench compiler_benchmark
# Run specific benchmark by name
cargo bench --bench compiler_benchmark bench_incremental_add_user_field
# Run with output
cargo bench --bench compiler_benchmark -- --nocapture
benches/incremental/)Measure incremental compilation performance when files change in multi-file projects.
How it works:
before/ contains the initial project stateafter/ contains ONLY the files that changed (sparse directory)Current benchmarks:
add_user_field - Adding fields to an existing classrename_type - Renaming a type used across filesbenches/scale/)Test compiler performance with large files.
Current benchmarks:
100_functions.baml - File with 100 function definitionsdeep_nesting.baml - Deeply nested type hierarchiesbenches/realistic/)Complete, real-world BAML projects for end-to-end performance testing.
Create a new directory under benches/incremental/your_benchmark/
Add the initial project state to before/:
benches/incremental/your_benchmark/
├── before/
│ ├── models.baml
│ ├── functions.baml
│ └── clients.baml
Add ONLY changed files to after/:
├── after/
│ └── models.baml # Only this file changed
For file deletions, create an empty .delete marker:
├── after/
│ └── old_file.baml.delete # Empty file marking deletion
Add a description.md explaining the change
Simply add a .baml file to benches/scale/:
benches/scale/your_benchmark.baml
Create a complete project under benches/realistic/:
benches/realistic/your_app/
├── models/
├── functions/
└── clients/
The benchmark system uses a build script (bench_build.rs) to automatically discover and generate benchmarks at compile time.
Key features:
after/ directories for incremental changes.delete markersWhen you run benchmarks, you'll see output like:
test bench_incremental_add_user_field ... bench: 5,234 ns/iter (+/- 512)
test bench_incremental_rename_type ... bench: 15,678 ns/iter (+/- 1,234)
test bench_scale_100_functions ... bench: 45,123 ns/iter (+/- 3,456)
The time shown is per iteration. Lower is better.
after/Benchmarks are run in CI to track performance over time. Significant regressions will be flagged.
.baml extensionbefore/ and after/ directories exist for incremental benchmarkscargo clean and rebuildafter/ only contains changed files.delete markers are empty files