Repository navigation
ci: add CodSpeed benchmarks for macro expansion - #316
Open
codspeed[bot] wants to merge 1 commit into
Open
codspeed[bot] wants to merge 1 commit into
codspeed[bot] wants to merge 1 commit into
Conversation
Author
Congrats! CodSpeed is installed 🎉
You will start to see performance impacts in the reports once the benchmarks are run from your default branch.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theirproc_macro2entry 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,widewith 10 columns,fully_annotatedlike the budget tests, andrelatedwith belongs_to/has_many/filters/column constraints) run through:entity_parse: attribute parsing intoEntityDef(darling)entity_expand: the full#[derive(Entity)]pipeline (entity::expand)entity_expand_to_string: expansion plus rendering to source textentity_parse_source_and_expand:synparsing of the item source plus expansion, end to endThere are also two single benchmarks:
entity_error_expand(EntityError) andvalue_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:divandev-dependency (codspeed-divan-compat) and the[[bench]]targetsrc/error.rs,src/value_object.rs:generateis nowpub(crate)so the bench can call it, likeentity::expandalready is.github/workflows/codspeed.yml: runs the benchmarks in CodSpeed's CPU simulation mode on pushes tomain, 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 badgecargo clippy -p entity-derive-impl --bench expand --all-features -- -D warningsis 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-implNext steps
maingets a baseline. After that, pull requests get performance reports comparing against it.Comment
@codspeedbot <request>(for example, "add a benchmark for an entity with commands and streams") and I'll do it.