Skip to content

chore: move to criterion benches from nightly#709

Merged
clarfonthey merged 3 commits intorust-lang:masterfrom
0xdeafbeef:benches
Apr 6, 2026
Merged

chore: move to criterion benches from nightly#709
clarfonthey merged 3 commits intorust-lang:masterfrom
0xdeafbeef:benches

Conversation

@0xdeafbeef
Copy link
Copy Markdown
Contributor

Shape of benches is mostly unchanged. Most of noise comes from switching from #[bench] to passing c and using c.bench_function.

I've changed insert bench to allocate outside of the loop, can revert to prev behavior.

And I'm not sure about ci, should we only check that benches compile or run only on linux? Full suit takes a lot of time and without saving results it looks wastefull.

Follow-up to #707 (comment)

@0xdeafbeef
Copy link
Copy Markdown
Contributor Author

@clarfonthey also mb it's a good idea to make loop bodies separate functions, so it doesn't cause duplication when adopted to gungraun. But I've tried to make changes minimal

Comment thread benches/bench.rs
extern crate test;

use test::{Bencher, black_box};
#![expect(missing_docs)] // criterion_group! generates a public bench entrypoint
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until a better solution arises, I'm fine just adding this line to every dedicated test/bench module tbh. Right now we don't really have a way to say "missing docs on non-test items"

@clarfonthey
Copy link
Copy Markdown
Contributor

Honestly, there are plenty of things to criticise about the benchmarks, but since this is just strictly an improvement, I'm inclined to just merge this as-is so we can nitpick the actual benchmark code separately. But I'll wait a bit and take a fresh look for anything particularly egregious in a bit before merging.

@clarfonthey
Copy link
Copy Markdown
Contributor

Re: "should we just check that everything compiles," I made a mistake when updating ci/tools.sh and clippy is run on --all (alias for --workspace, which is redundant here) instead of --all-targets, which would just lint all the code in the project and perform cargo check on it. (This also would make --tests redundant as well.)

Benchmarking in CI is not only costly but also very susceptible to noise so I would recommend against it for statistical benches. It might be worth running a small gungraun benchmark on every target though, but we can visit that later.

@0xdeafbeef
Copy link
Copy Markdown
Contributor Author

0xdeafbeef commented Apr 4, 2026

Re: "should we just check that everything compiles," I made a mistake when updating ci/tools.sh and clippy is run on --all (alias for --workspace, which is redundant here) instead of --all-targets, which would just lint all the code in the project and perform cargo check on it. (This also would make --tests redundant as well.)

Benchmarking in CI is not only costly but also very susceptible to noise so I would recommend against it for statistical benches. It might be worth running a small gungraun benchmark on every target though, but we can visit that later.

I mean

"${CARGO}" -vv bench "${NO_RUN}" --features "${FEATURES}"

is triggered for every nightly test

image

https://github.com/rust-lang/hashbrown/actions/runs/23953355374/job/69866090026

The question I wanted to ask is: should I preserve it, remove the run entirely, run only a single iteration, or do something else?

Criterion takes much longer to run than the nightly bench.

update:

You can it here:

https://github.com/rust-lang/hashbrown/actions/runs/23945600072/job/69841110628?pr=709

17 minutes vs 3 minutes before

@clarfonthey
Copy link
Copy Markdown
Contributor

Oh, I had totally forgotten about those, and agree that we can replace them with just running clippy for now. Statistical tests don't really work well in CI due to all the noise.

@0xdeafbeef
Copy link
Copy Markdown
Contributor Author

Oh, I had totally forgotten about those, and agree that we can replace them with just running clippy for now. Statistical tests don't really work well in CI due to all the noise.

OK, so I'll edit ci.sh?

@clarfonthey
Copy link
Copy Markdown
Contributor

Figured out how to push changes to the branch after much frustration, but that was the specific changes I was thinking of. (Since they're not included in the diff, I can't just suggest them there.)

@0xdeafbeef
Copy link
Copy Markdown
Contributor Author

Do you want any other changes? I can port what we have now to Gangraun. Personally, I’m thinking of storing a JSON in the repo and having CI track whether the number has changed since the last run by more than some delta, plus a job that posts comments on PRs with diff and instructions for updating this JSON

@clarfonthey
Copy link
Copy Markdown
Contributor

Honestly, was mostly waiting for you to notice the changes I made + take another look before merging. Stuff like porting to gungraun can happen in a second PR.

@clarfonthey
Copy link
Copy Markdown
Contributor

So, the only thing that I think might be worth doing in this PR (and if you'd rather do it later, that's fine) is combining the benches into a single package; separating them into files is still fine. Since they can be filtered by name, it feels better to just combine them into one place, and it would simplify Cargo.toml too.

Right now, the benches otherwise don't seem to be well organised and it feels like it just increases friction to have them separated into different packages like this.

(crates? packages? benches? the terminology is weird here since the individual benchmarks feel like benches, but according to cargo, the whole module is a separate bench.)

@0xdeafbeef
Copy link
Copy Markdown
Contributor Author

Honestly, was mostly waiting for you to notice the changes I made + take another look before merging. Stuff like porting to gungraun can happen in a second PR.

And i was waiting for you :) I'd change the same

@0xdeafbeef
Copy link
Copy Markdown
Contributor Author

So, the only thing that I think might be worth doing in this PR (and if you'd rather do it later, that's fine) is combining the benches into a single package; separating them into files is still fine. Since they can be filtered by name, it feels better to just combine them into one place, and it would simplify Cargo.toml too.

Right now, the benches otherwise don't seem to be well organised and it feels like it just increases friction to have them separated into different packages like this.

(crates? packages? benches? the terminology is weird here since the individual benchmarks feel like benches, but according to cargo, the whole module is a separate bench.)

I'll merge them

@0xdeafbeef
Copy link
Copy Markdown
Contributor Author

@clarfonthey done

@clarfonthey clarfonthey added this pull request to the merge queue Apr 6, 2026
Merged via the queue into rust-lang:master with commit b1c4403 Apr 6, 2026
25 checks passed
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