Skip to content

Implement --perf flag to lintcheck for benchmarking #14116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2025

Conversation

blyxyas
Copy link
Member

@blyxyas blyxyas commented Jan 30, 2025

Turns out I was completely overcomplicating myself,
there was no need for an external tool such as becnhv2
or even the original becnh, we already had the benchmarking
infrastructure right under our noses!

This PR implements a new lintcheck option called
--perf, using it as a flag will mean that lintcheck
builds Clippy as a release package and hooks perf to it.

The realization that lintcheck is already 90% of what
a benchmarking tool needs came to me in a dream ☁️

changelog:none

Turns out I was completely overcomplicating myself,
there was no need for an external tool such as becnhv2
or even the original becnh, we already had the benchmarking
infrastructure right under our noses!

This PR implements a new **lintcheck** option called
--perf, using it as a flag will mean that lintcheck
builds Clippy as a release package and hooks perf to it.

The realization that lintcheck is already 90% of what
a benchmarking tool needs came to me in a dream.
@rustbot
Copy link
Collaborator

rustbot commented Jan 30, 2025

r? @Alexendoo

rustbot has assigned @Alexendoo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 30, 2025
@@ -46,6 +46,11 @@ pub(crate) struct LintcheckConfig {
/// Run clippy on the dependencies of crates specified in crates-toml
#[clap(long, conflicts_with("max_jobs"))]
pub recursive: bool,
/// Also produce a `perf.data` file, implies --jobs=1,
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't look like this implies is true currently, there might be a #[clap] flag for it though

Copy link
Member Author

Choose a reason for hiding this comment

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

I realized it immediately after uploading the issue, just updated it to actually imply (declare a default value, and exit if it the flags don't comply)

Comment on lines 237 to 264
fn build_clippy() -> String {
fn build_clippy(release_build: bool) -> String {
let output = Command::new("cargo")
.args(["run", "--bin=clippy-driver", "--", "--version"])
.args([
"run",
"--bin=clippy-driver",
if release_build { "-r" } else { "" },
"--",
"--version",
])
.stderr(Stdio::inherit())
Copy link
Member

Choose a reason for hiding this comment

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

Would we want to bump up CARGO_PROFILE_RELEASE_DEBUG when perf is enabled too?

Comment on lines 289 to 294
if config.perf && config.max_jobs != 1 {
eprintln!(
"Lintcheck's --perf flag must be triggered only with 1 job,\nremove either the --jobs/-j flag or the --perf flag"
);
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Should be able to use Clap's conflicts_with for this

"--",
"cargo",
]);
cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true");
Copy link
Member

Choose a reason for hiding this comment

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

This would want to go in build_clippy as we want the debuginfo on the built clippy rather than the packages we're linting

Copy link
Member

@Alexendoo Alexendoo left a comment

Choose a reason for hiding this comment

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

👍

@Alexendoo Alexendoo added this pull request to the merge queue Feb 2, 2025
Merged via the queue into rust-lang:master with commit 6d1482c Feb 2, 2025
11 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Mar 23, 2025
In #14116 we added a benchmarking option for Lintcheck, this commit adds
a new chapter to the book AND improves that option into a more usable
state.

It's recommended to review one commit at a time.

- **Document how to benchmark with lintcheck --perf**
- **Several improvements on lintcheck perf (desc.)**

    - Now lintcheck perf deletes target directory after benchmarking,
benchmarking with a cache isn't very useful or telling of any
precise outcome.

    - Support for benchmarking several times without having to do
a cargo clean.

    - Compress perf.data

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants