Skip to content

Significantly optimize significant_drop_tightening #10533

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 1 commit into from
Mar 23, 2023

Conversation

Noratrieb
Copy link
Member

The lint is very slow as it doesn't cache the deeply nested check for the attribute. If we cache it, we can reduce the time spent on checking rustc_borrowck from 28s to 9s, which is a nice improvement. In the profile, the time inside has_sig_drop_attr goes from 66% to 0.2%, which is a lot more reasonable.

Flame graphs

Before (all the tall clippy towers are has_sig_drop_attr):
before

After:
after

Fixes #10532

changelog: [significant_drop_tightening]: significantly optimized

@rustbot
Copy link
Collaborator

rustbot commented Mar 22, 2023

r? @dswij

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 22, 2023
The lint is very slow as it doesn't cache the deeply nested check for
the attribute. If we cache it, we can reduce the time spent on checking
`rustc_borrowck` from 28s to 9s, which is a nice improvement. In the
profile, the time inside `has_sig_drop_attr` goes from 66% to 0.2%,
which is a lot more reasonable.

See the PR for nice graphs.
@Noratrieb
Copy link
Member Author

I'd also like to nominate this for a beta backport (if the lint is in beta already, which I think it is), as this seems to affect uses where nursery was never enabled (which is kinda weird?).

Comment on lines 59 to +61
/// Auxiliary structure used to avoid having to verify the same type multiple times.
seen_types: FxHashSet<Ty<'tcx>>,
type_cache: FxHashMap<Ty<'tcx>, bool>,
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need both? Is type_cache not enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need one for cycle detection (during the recursive call) and one for caching (after the recursive call)

Copy link
Member

@dswij dswij left a comment

Choose a reason for hiding this comment

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

Oh sweet, thanks for this!

@dswij
Copy link
Member

dswij commented Mar 23, 2023

as this seems to affect uses where nursery was never enabled

That's odd. How does the lint affect non-nursery uses? Does the lint fire even when nursery is not enabled?

@dswij
Copy link
Member

dswij commented Mar 23, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Mar 23, 2023

📌 Commit 966d5b0 has been approved by dswij

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Mar 23, 2023

⌛ Testing commit 966d5b0 with merge be01b98...

@bors
Copy link
Contributor

bors commented Mar 23, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: dswij
Pushing be01b98 to master...

@bors bors merged commit be01b98 into rust-lang:master Mar 23, 2023
@Noratrieb Noratrieb deleted the cache branch March 23, 2023 09:35
@dswij dswij added beta-nominated Nominated for backporting to the compiler in the beta channel. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 23, 2023
@Alexendoo
Copy link
Member

That's odd. How does the lint affect non-nursery uses? Does the lint fire even when nursery is not enabled?

The lint pass still runs but the lint won't be emitted if it's not enabled, related: rust-lang/rust#106983

@flip1995
Copy link
Member

rust-lang/rust#110273

@flip1995 flip1995 added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels Apr 13, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 13, 2023
[beta] Clippy: backport optimization and ICE fixes

The first commit optimizes a lint, that runs noticeably slow and is a perf issue. See rust-lang/rust-clippy#10533

The second commit fixes an ICE that occurred when running Clippy on `gitoxide` besides others. Since this is a rather popular crate, we want to fix this rather sooner than later. See rust-lang/rust-clippy#10403

---

Both commits are already on `master` and deployed on `nightly`.
@xFrednet
Copy link
Member

This doesn't require a changelog entry, as it was ported to the same version that introduced the lint :).

Thank you for the backport

@rustbot label -beta-accepted

@rustbot rustbot removed the beta-accepted Accepted for backporting to the compiler in the beta channel. label Apr 19, 2023
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.

significant_drop_tightening is very slow
8 participants