Skip to content

ci: add benchmarks and CodSpeed performance tracking - #149

Merged
RAprogramm merged 2 commits into
mainfrom
codspeed/setup-benchmarks
Nov 25, 2026
Merged

RAprogramm merged 2 commits into
mainfrom
codspeed/setup-benchmarks

Conversation

@codspeed

@codspeed codspeed Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds benchmarks for the static analysis pipeline and runs them with CodSpeed on every pull request and on main. CodSpeed posts a report on each pull request that compares every benchmark with main and flags regressions before merge. The CodSpeed report on this PR lists all 17 benchmarks.

What changed

Benchmarks (benches/analyzer.rs), written with divan through codspeed-divan-compat (dev-dependency only, renamed to divan). They cover the code that runs on every CLI invocation:

Benchmark What it measures
parse_queries_generic[10/100], parse_queries_postgres[10/100] parse_queries on a mix of 20 query shapes (joins, CTEs, subqueries, IN lists, UNION, INSERT/UPDATE/DELETE)
parse_schema_generic Schema::parse of 60 tables with indexes
parse_schema_clickhouse, preprocess_clickhouse ClickHouse DDL with CODEC, PARTITION BY and SETTINGS
analyze_rules[10/100], analyze_rules_with_schema[10/100] RuleRunner::analyze with all rules, without and with the schema-aware rules
build_rule_runner_with_schema Building the rule runner from a schema
format_report[text/json/sarif] format_static_analysis for a 100-query report
full_static_pipeline[10/100] Schema parse + query parse + rules + text output, as analyze does without file I/O and LLM calls

The benchmark binary runs rayon on one thread. CodSpeed's CPU simulation counts CPU work, and with several rayon threads the results moved by up to 12% between identical runs because of thread scheduling. With one thread, two runs gave the same numbers.

CI (.github/workflows/codspeed.yml): builds the benchmarks with cargo-codspeed and runs them with CodSpeedHQ/action v5.8.0 in simulation mode. Authentication uses OIDC (id-token: write), so no secret token is needed. Actions are pinned by commit hash like the other workflows. benches/** is also added to the Rust paths filter in _detect.yml, so fmt and clippy run when only benchmarks change.

README: CodSpeed badge, and a short "Benchmarks" section under "Performance" with the commands to run them locally.

Build fix (src/query/extract/expr.rs): main does not compile right now. Dependabot bumped sqlparser to 0.64 in #144, and 0.64 merged Expr::InList and Expr::InSubquery into Expr::In { target: InTarget, .. }. The four match arms now use Expr::In with InTarget::List / InTarget::Subquery. The behavior stays the same: other targets (such as UNNEST) fell through to _ before and still do. All tests pass (cargo test --all-features, and the Test job here). This is in its own commit, so it can be split out if you prefer.

Running locally

cargo bench --bench analyzer

# With the CodSpeed CLI
cargo install cargo-codspeed --locked
cargo codspeed build -m simulation
codspeed run -m simulation -- cargo codspeed run

CI status

  • audit and deny fail, and so CI Success fails. This PR does not cause it: the advisories are for rustls 0.23.43 (RUSTSEC-2026-0285, -0346, -0348, -0349, -0382) and url 2.5.8 (RUSTSEC-2026-0592), which are already in Cargo.lock on main. These jobs run here because Cargo.lock changed. cargo update -p rustls -p url in a separate PR should fix them. Licenses and bans pass for the new dev-dependencies.
  • All other checks pass, including CodSpeed, Test, Clippy, Format, MSRV, Machete, REUSE and Zizmor.

Notes

  • The CodSpeed report warns that 12 benchmarks spend much time in system calls. This comes from rayon waking its worker thread on each parallel call. CPU simulation leaves system calls out, so the numbers show CPU work only. They are still stable from run to run.
  • preprocess_clickhouse is slow for its job (about 26 ms in CI for 40 tables): normalize_whitespace compiles a new Regex on every call.
  • Possible bug, not fixed here: in the ClickHouse preprocessor, TTL_REGEX also removes the terminating ;. A schema with a TTL table followed by another statement, or with TTL ... SETTINGS ..., fails to parse. For this reason the ClickHouse benchmark input does not use TTL.
  • The benchmarks use CPU simulation on ubuntu-latest. It counts instructions, so results do not depend on the noise of the CI machine.

Comment this and I'll do it:

@codspeedbot optimize preprocess_clickhouse

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
@github-actions

Copy link
Copy Markdown
Contributor

Rust Diff Analysis

Tip

PR size is within limits. Good job keeping changes focused!

Limits — configured thresholds for this repository

Each metric is compared against its configured maximum. If any limit is exceeded, the PR check fails.

Metric Value Limit Status
Production Units 2 30 ✅
Weighted Score 6 100 ✅
Lines Added 12 200 ✅

Understanding the metrics:

  • Production Units: Functions, structs, enums, traits, and other semantic code units in production code
  • Weighted Score: Complexity score based on unit types (public APIs weigh more than private)
  • Lines Added: Raw count of new lines in production code
Summary — breakdown of changes by category

Production code counts toward limits. Test code is tracked but doesn't affect limits.

Metric Production Test
Functions 2 -
Structs/Enums 0 -
Other 0 -
Lines added +12 +156
Lines removed -9 -0
Total units 2 21
Production Changes — 2 units modified

Semantic units (functions, structs, etc.) that were added or modified in production code.

File Unit Type Changes
src/query/extract/expr.rs:6-111 extract_columns_from_expr function +7 -5
src/query/extract/expr.rs:187-223 contains_subquery function +5 -4
Test Changes — 21 units modified

Test code changes don't count toward PR size limits.

File Unit Type Changes
benches/analyzer.rs:17-25 main function +9 -0
benches/analyzer.rs:27-28 SIZES const +2 -0
benches/analyzer.rs:30-31 SCHEMA_TABLES const +2 -0
benches/analyzer.rs:33-54 QUERY_TEMPLATES const +22 -0
benches/analyzer.rs:56-64 queries_sql function +9 -0
benches/analyzer.rs:66-78 schema_sql function +13 -0
benches/analyzer.rs:80-91 clickhouse_schema_sql function +12 -0
benches/analyzer.rs:93-95 parsed_schema function +3 -0
benches/analyzer.rs:97-99 parsed_queries function +3 -0
benches/analyzer.rs:101-104 report function +4 -0
benches/analyzer.rs:106-112 output_options function +7 -0
benches/analyzer.rs:114-118 parse_queries_generic function +5 -0
benches/analyzer.rs:120-124 parse_queries_postgres function +5 -0
benches/analyzer.rs:126-130 parse_schema_generic function +5 -0
benches/analyzer.rs:132-136 parse_schema_clickhouse function +5 -0
benches/analyzer.rs:138-143 preprocess_clickhouse function +6 -0
benches/analyzer.rs:145-150 analyze_rules function +6 -0
benches/analyzer.rs:152-157 analyze_rules_with_schema function +6 -0
benches/analyzer.rs:159-165 build_rule_runner_with_schema function +7 -0
benches/analyzer.rs:167-177 format_report function +11 -0
benches/analyzer.rs:179-192 full_static_pipeline function +14 -0
Analysis Scope

Analyzed: 2 Rust files

Skipped files:

  • 5 non-Rust files

Skipped file list:

  • .github/workflows/_detect.yml (non-Rust)
  • .github/workflows/codspeed.yml (non-Rust)
  • Cargo.lock (non-Rust)
  • Cargo.toml (non-Rust)
  • README.md (non-Rust)

Rust Diff Analyzer

@github-actions

Copy link
Copy Markdown
Contributor

Cargo Quality Analysis

Tip

All quality checks passed. Code meets all standards!

Results — issues found by each analyzer

Each analyzer checks for specific code patterns. Zero issues means the check passed.

Analyzer Issues Status
path_import 0 ✅
format_args 0 ✅
empty_lines 0 ✅
inline_comments 0 ✅
mod_rs 0 ✅
Total 0
Analyzers — what each check does

These analyzers enforce consistent code style and best practices.

Analyzer Description How to fix
path_import Detects inline path imports like std::path::Path Use use statements at the top
format_args Detects format!("{}", x) patterns Use format!("{x}") syntax
empty_lines Detects empty lines inside function bodies Remove extra blank lines
inline_comments Detects // comment inside functions Move to doc comments or remove
mod_rs Detects mod.rs files (use modern module style) Rename foo/mod.rs to foo.rs
Raw Output — detailed analysis log
Total issues: 0
Fixable: 0

Cargo Quality

@codspeed

codspeed Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Congrats! CodSpeed is installed 🎉

🆕 17 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

1 warning

⚠️ 12 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

Detected benchmarks


Open in CodSpeed

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed
codspeed Bot requested a review from RAprogramm November 25, 2026 01:54
@codspeed
codspeed Bot marked this pull request as ready for review November 25, 2026 01:54
@RAprogramm
RAprogramm merged commit 9b40ac8 into main Nov 25, 2026
28 of 31 checks passed
@RAprogramm
RAprogramm deleted the codspeed/setup-benchmarks branch November 25, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants