Skip to content

ci: add CodSpeed benchmarks for macro expansion - #316

Open
codspeed[bot] wants to merge 1 commit into
mainfrom
codspeed/setup-benchmarks
Open

codspeed[bot] wants to merge 1 commit into
mainfrom
codspeed/setup-benchmarks

Conversation

@codspeed

@codspeed codspeed Bot commented Nov 5, 2026

Copy link
Copy Markdown

Summary

This PR adds continuous performance tracking with CodSpeed. The benchmarks measure how fast the derive macros expand, since every downstream build pays that cost.

How the harness works

Nothing can link a proc-macro crate, so the benchmark (crates/entity-derive-impl/benches/expand.rs) compiles the macro sources straight into the bench binary. It does this with a #[path = "../src"] inline module and re-exports the modules at the crate root, so the sources' crate:: paths still resolve. The pipelines run through their proc_macro2 entry points, which also work outside a compiler expansion context. The library itself does not change, except for two small visibility tweaks.

The benchmarks use divan via codspeed-divan-compat. Four reference entities (minimal, wide with 10 columns, fully_annotated like the budget tests, and related with belongs_to/has_many/filters/column constraints) run through:

  • entity_parse: attribute parsing into EntityDef (darling)
  • entity_expand: the full #[derive(Entity)] pipeline (entity::expand)
  • entity_expand_to_string: expansion plus rendering to source text
  • entity_parse_source_and_expand: syn parsing of the item source plus expansion, end to end

There are also two single benchmarks: entity_error_expand (EntityError) and value_object_expand (ValueObject).

Before measuring, I checked that every reference input expands without emitting compile_error!.

Changes

  • crates/entity-derive-impl/benches/expand.rs: new benchmark suite (18 benchmarks)
  • crates/entity-derive-impl/Cargo.toml: divan dev-dependency (codspeed-divan-compat) and the [[bench]] target
  • src/error.rs, src/value_object.rs: generate is now pub(crate) so the bench can call it, like entity::expand already is
  • .github/workflows/codspeed.yml: runs the benchmarks in CodSpeed's CPU simulation mode on pushes to main, on pull requests and on manual dispatch. It authenticates through OIDC, so no token secret is needed. Actions are pinned by commit hash, like the rest of the workflows.
  • README.md: CodSpeed badge

cargo clippy -p entity-derive-impl --bench expand --all-features -- -D warnings is clean. The bench file is formatted with the repository's nightly rustfmt config.

Running locally

cargo bench -p entity-derive-impl --bench expand
# or, with CodSpeed instrumentation
cargo codspeed build -m simulation -p entity-derive-impl
codspeed run -m simulation -- cargo codspeed run -p entity-derive-impl

Next steps

  • Merge this PR so main gets a baseline. After that, pull requests get performance reports comparing against it.
  • Optionally, enable performance checks to flag regressions in PRs.
  • When a new generator lands, add a reference entity or argument that uses it.

Comment @codspeedbot <request> (for example, "add a benchmark for an entity with commands and streams") and I'll do it.

@codspeed

codspeed Bot commented Nov 5, 2026

Copy link
Copy Markdown
Author

Congrats! CodSpeed is installed 🎉

🆕 18 new benchmarks were detected.

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

Detected benchmarks


Open in CodSpeed

@codspeed
codspeed Bot marked this pull request as ready for review November 5, 2026 06:37
@codspeed
codspeed Bot requested a review from RAprogramm as a code owner November 5, 2026 06:37

This branch has not been deployed

No deployments
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.

0 participants