Skip to content

Conversation

samueltardieu
Copy link
Member

Two optimizations have been done when checking for the context in which to apply the lint:

  • Checking for the mere presence of comments does not require building a String with the comment to then check if it is empty and discard it.
  • Checking for the presence of comment can be done after we have checked that we do have a if construct that we intend to lint instead of for every expression.

changelog: none

r? blyxyas

@samueltardieu samueltardieu added the G-performance-project Goal: For issues and PRs related to the Clippy Performance Project label Aug 6, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 6, 2025
@samueltardieu
Copy link
Member Author

Performance improvements have not been measured experimentally, this is only a reaction to #clippy > Clippy's performance "monthly" update @ 💬.

Copy link
Member

@blyxyas blyxyas left a comment

Choose a reason for hiding this comment

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

Just a naming nit, just verified it in bumpalo and the lint has gone down from 6.3 million instructions to 179k. That's a 97.1% perf. improvement for the lint.

Great!

&& let Some(higher::If {
cond,
then,
r#else: Some(r#else),
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be more ergonomic to get rid of this r#else block and just call it else_block. I'm not sure why we have so many r#.. identifiers when they're so awkward to use.

Suggested change
r#else: Some(r#else),
r#else: Some(else_block),

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed into else_expr, since it might not be a block (only the then is guaranteed to be one).

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Aug 6, 2025
Two optimizations have been done when checking for the context in which
to apply the lint:

- Checking for the mere presence of comments does not require building a
  `String` with the comment to then check if it is empty and discard it.
- Checking for the presence of comment can be done after we have checked
  that we do have a `if` construct that we intend to lint instead of for
  every expression.
@samueltardieu samueltardieu force-pushed the optimize-needless-bool branch from 87a2a7a to 8602faa Compare August 6, 2025 17:49
@samueltardieu samueltardieu requested a review from blyxyas August 6, 2025 17:50
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Aug 6, 2025
Copy link
Member

@blyxyas blyxyas left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! ❤️ 🌈

@blyxyas blyxyas added this pull request to the merge queue Aug 6, 2025
Merged via the queue into rust-lang:master with commit 4cb43f4 Aug 6, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 6, 2025
@samueltardieu samueltardieu deleted the optimize-needless-bool branch August 9, 2025 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

G-performance-project Goal: For issues and PRs related to the Clippy Performance Project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants