Skip to content
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

Rewrite lint_expectations in a single pass. #127313

Merged
merged 4 commits into from
Sep 1, 2024

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Jul 4, 2024

This PR aims at reducing the perf regression from #120924 (comment) with drive-by simplifications.

Basically, instead of using the lint level builder, which is slow, this PR splits lint_expectations logic in 2:

  • listing the LintExpectations is done in shallow_lint_levels_on, on a per-owner basis;
  • building the unstable->stable expectation id map is done by iterating on attributes.

r? ghost for perf

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 4, 2024
@cjgillot
Copy link
Contributor Author

cjgillot commented Jul 4, 2024

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 4, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 4, 2024
Rewrite lint_expectations in a single pass.

This PR aims at reducing the perf regression from rust-lang#120924 (comment) with drive-by simplifications.

Basically, instead of using the lint level builder, which is slow, this PR splits `lint_expectations` logic in 2:
- listing the `LintExpectations` is done in `shallow_lint_levels_on`, on a per-owner basis;
- building the unstable->stable expectation id map is done by iterating on attributes.

r? ghost for perf
@bors
Copy link
Contributor

bors commented Jul 4, 2024

⌛ Trying commit 66a9985 with merge 809e06b...

@bors
Copy link
Contributor

bors commented Jul 4, 2024

☀️ Try build successful - checks-actions
Build commit: 809e06b (809e06bc005b736706b134a829fb59e278eb6017)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (809e06b): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.5%] 15
Regressions ❌
(secondary)
0.7% [0.3%, 1.4%] 12
Improvements ✅
(primary)
-0.5% [-1.5%, -0.2%] 70
Improvements ✅
(secondary)
-0.7% [-1.6%, -0.2%] 42
All ❌✅ (primary) -0.4% [-1.5%, 0.5%] 85

Max RSS (memory usage)

Results (primary -5.5%, secondary -2.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-5.5% [-5.5%, -5.5%] 1
Improvements ✅
(secondary)
-2.2% [-4.2%, -0.9%] 8
All ❌✅ (primary) -5.5% [-5.5%, -5.5%] 1

Cycles

Results (primary 1.5%, secondary 1.6%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.9% [2.1%, 4.0%] 11
Regressions ❌
(secondary)
1.6% [0.5%, 2.1%] 7
Improvements ✅
(primary)
-1.3% [-1.9%, -0.9%] 5
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.5% [-1.9%, 4.0%] 16

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 738.413s -> 735.235s (-0.43%)
Artifact size: 328.22 MiB -> 328.15 MiB (-0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 4, 2024
@cjgillot cjgillot marked this pull request as ready for review July 4, 2024 23:05
@cjgillot
Copy link
Contributor Author

cjgillot commented Jul 4, 2024

r? compiler

@cjgillot
Copy link
Contributor Author

cjgillot commented Jul 4, 2024

Perf: the results are an improvement almost everywhere. The regressions (externs, unused-warnings) appear due to more calls to shallow_lint_levels_on and associated query overhead.

@cjgillot
Copy link
Contributor Author

cjgillot commented Jul 4, 2024

cc @xFrednet

@cjgillot
Copy link
Contributor Author

r? compiler

@rustbot rustbot assigned jieyouxu and unassigned compiler-errors Aug 31, 2024
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks, this LGTM for the most part, but I'm not super sure about how the AttrId <-> HirId mapping is constructed.

Comment on lines +37 to +41
// Some attributes appear multiple times in HIR, to ensure they are correctly taken
// into account where they matter. This means we cannot just associate the AttrId to
// the first HirId where we see it, but need to check it actually appears in a lint
// level.
// FIXME(cjgillot): Can this cause an attribute to appear in multiple expectation ids?
Copy link
Member

@jieyouxu jieyouxu Sep 1, 2024

Choose a reason for hiding this comment

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

Discussion: this seems a little suspicious to me, in that I would've expected AttrId <-> HirId to be a bijective map. "Some attributes appear multiple times in HIR, to ensure they are correctly taken into account where they matter" almost sounds like a bug to me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This FIXME makes me sad too, and triggered the discussion here: #127884 (comment)

This map is not bijective, but it is well-defined in one direction. From a pair (HirId, attr_index), you'll get a single AttrId, but the converse is not true.

Copy link
Member

@jieyouxu jieyouxu Sep 1, 2024

Choose a reason for hiding this comment

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

Thanks for the clarification, that discussion was enlightening. I feel like this will cause a bug somewhere but I also can't immediately come up with an example for. As I can't come up with an example, I'm inclined to merge this as-is and see what cases we run into in practice through fuzzing and whatnot. And see if we can come up with a scheme that is more robust.

Copy link
Member

@jieyouxu jieyouxu Sep 1, 2024

Choose a reason for hiding this comment

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

(Side remark: our lint infra and lint level computation is unfortunately incredibly convoluted)

tests/ui/error-codes/E0602.stderr Show resolved Hide resolved
@jieyouxu jieyouxu added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 1, 2024
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

I'm okay with accepting the FIXME even if it may cause bugs, because the logic before the rework is also not exactly watertight. The perf change seems to be mixed leaning towards more improvements so I don't feel like it's blocking.

@jieyouxu
Copy link
Member

jieyouxu commented Sep 1, 2024

In any case, I think rewriting into a single pass also makes the logic clearer than before.

@bors r+

@bors
Copy link
Contributor

bors commented Sep 1, 2024

📌 Commit ff1fc68 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 1, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Sep 1, 2024

@bors rollup=never (perf significant)

@bors
Copy link
Contributor

bors commented Sep 1, 2024

⌛ Testing commit ff1fc68 with merge a48861a...

@bors
Copy link
Contributor

bors commented Sep 1, 2024

☀️ Test successful - checks-actions
Approved by: jieyouxu
Pushing a48861a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 1, 2024
@bors bors merged commit a48861a into rust-lang:master Sep 1, 2024
7 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 1, 2024
@cjgillot cjgillot deleted the single-expect branch September 1, 2024 18:55
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a48861a): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.4% [0.3%, 0.6%] 10
Regressions ❌
(secondary)
0.8% [0.4%, 1.5%] 10
Improvements ✅
(primary)
-0.5% [-1.5%, -0.2%] 71
Improvements ✅
(secondary)
-0.8% [-1.8%, -0.3%] 52
All ❌✅ (primary) -0.4% [-1.5%, 0.6%] 81

Max RSS (memory usage)

Results (primary 0.3%, secondary 0.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.8% [0.4%, 2.4%] 49
Regressions ❌
(secondary)
1.0% [0.4%, 3.1%] 42
Improvements ✅
(primary)
-1.0% [-3.3%, -0.4%] 18
Improvements ✅
(secondary)
-0.7% [-1.9%, -0.4%] 39
All ❌✅ (primary) 0.3% [-3.3%, 2.4%] 67

Cycles

Results (primary -0.4%, secondary -0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.0% [0.4%, 4.2%] 22
Regressions ❌
(secondary)
1.2% [0.4%, 5.2%] 57
Improvements ✅
(primary)
-0.8% [-3.3%, -0.4%] 83
Improvements ✅
(secondary)
-1.2% [-4.4%, -0.4%] 58
All ❌✅ (primary) -0.4% [-3.3%, 4.2%] 105

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 790.965s -> 787.22s (-0.47%)
Artifact size: 338.44 MiB -> 338.38 MiB (-0.02%)

@lqd
Copy link
Member

lqd commented Sep 3, 2024

updated results:

image

@Kobzol
Copy link
Contributor

Kobzol commented Sep 3, 2024

Many more improvements than regressions.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants