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

rustc_metadata: Switch all decoder methods from vectors to iterators #92245

Merged
merged 1 commit into from
Jan 16, 2022

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Dec 24, 2021

To avoid allocations in some cases.

Also remove unnecessary is_proc_macro_crate checks from decoder, currently the general strategy is to shift all the work to the encoder and assume that all the encoded data is correct and can be decoded unconditionally in the decoder.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 24, 2021
@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 24, 2021
@joshtriplett
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 24, 2021
@bors
Copy link
Contributor

bors commented Dec 24, 2021

⌛ Trying commit 2a074cf61105ad9a668719faa3a240e7d1f78c7e with merge a1b48ab4b3ea7e5795cb5b843b52edd696feaaf3...

@bors
Copy link
Contributor

bors commented Dec 24, 2021

☀️ Try build successful - checks-actions
Build commit: a1b48ab4b3ea7e5795cb5b843b52edd696feaaf3 (a1b48ab4b3ea7e5795cb5b843b52edd696feaaf3)

@rust-timer
Copy link
Collaborator

Queued a1b48ab4b3ea7e5795cb5b843b52edd696feaaf3 with parent 59337cd, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a1b48ab4b3ea7e5795cb5b843b52edd696feaaf3): comparison url.

Summary: This change led to small relevant mixed results 🤷 in compiler performance.

  • Small improvement in instruction counts (up to -0.4% on full builds of await-call-tree)
  • Small regression in instruction counts (up to 0.7% on incr-unchanged builds of helloworld)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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 led 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-review -S-waiting-on-perf +perf-regression

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 24, 2021
@petrochenkov petrochenkov 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 Dec 24, 2021
@petrochenkov
Copy link
Contributor Author

No idea what could cause the regressions here, maybe some unlucky new inlining choices, I'll check.

@petrochenkov petrochenkov changed the title rustc_metadata: Stop passing CrateMetadataRef by reference rustc_metadata: Stop passing CrateMetadataRef by reference (step 2) Dec 26, 2021
@petrochenkov
Copy link
Contributor Author

Blocked on #92277.

@petrochenkov petrochenkov added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 26, 2021
@bors

This comment has been minimized.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 8, 2022
rustc_metadata: Stop passing `CrateMetadataRef` by reference (step 1)

It's already a (fat) reference.
Double referencing it creates lifetime issues for its methods that want to return iterators.

---
Extracted from rust-lang#92245 for a perf run.
The PR changes a lot of symbol names due to function signature changes, so it's hard to do differential profiling, let's spend some machine time instead.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 9, 2022
rustc_metadata: Stop passing `CrateMetadataRef` by reference (step 1)

It's already a (fat) reference.
Double referencing it creates lifetime issues for its methods that want to return iterators.

---
Extracted from rust-lang#92245 for a perf run.
The PR changes a lot of symbol names due to function signature changes, so it's hard to do differential profiling, let's spend some machine time instead.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 10, 2022
rustc_metadata: Stop passing `CrateMetadataRef` by reference (step 1)

It's already a (fat) reference.
Double referencing it creates lifetime issues for its methods that want to return iterators.

---
Extracted from rust-lang#92245 for a perf run.
The PR changes a lot of symbol names due to function signature changes, so it's hard to do differential profiling, let's spend some machine time instead.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 13, 2022
rustc_metadata: Stop passing `CrateMetadataRef` by reference (step 1)

It's already a (fat) reference.
Double referencing it creates lifetime issues for its methods that want to return iterators.

---
Extracted from rust-lang#92245 for a perf run.
The PR changes a lot of symbol names due to function signature changes, so it's hard to do differential profiling, let's spend some machine time instead.
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Jan 14, 2022
@petrochenkov petrochenkov changed the title rustc_metadata: Stop passing CrateMetadataRef by reference (step 2) rustc_metadata: Switch all decoder methods from vectors to iterators Jan 14, 2022
@petrochenkov
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 14, 2022
@bors
Copy link
Contributor

bors commented Jan 14, 2022

⌛ Trying commit 14d56df404eb124a3599698edc6a53be9f30dca0 with merge 565e74827743aed951f73a4d339f5e9379afef9e...

@bors
Copy link
Contributor

bors commented Jan 14, 2022

☀️ Try build successful - checks-actions
Build commit: 565e74827743aed951f73a4d339f5e9379afef9e (565e74827743aed951f73a4d339f5e9379afef9e)

@rust-timer
Copy link
Collaborator

Queued 565e74827743aed951f73a4d339f5e9379afef9e with parent 86f7f78, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (565e74827743aed951f73a4d339f5e9379afef9e): comparison url.

Summary: This change led to small relevant improvements 🎉 in compiler performance.

  • Small improvement in instruction counts (up to -0.8% on incr-unchanged builds of cranelift-codegen)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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 led to changes in compiler perf.

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Jan 14, 2022
@petrochenkov petrochenkov removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 14, 2022
self.root.native_libraries.decode((self, sess)).collect()
}
fn get_native_libraries(self, sess: &'a Session) -> impl Iterator<Item = NativeLib> + 'a {
self.root.native_libraries.decode((self, sess))
Copy link
Member

Choose a reason for hiding this comment

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

Hm, it isn't entirely obvious to me that native_libraries will always decode to an empty list for is_proc_macro_crate() == true, though I'll admit that I didn't spend a long time spelunking the relevant code trying to figure out if there's any code elsewhere that ensures this property holds.

Is there any way it would make sense to add an assertion or something along the lines here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For proc macro crates encoder now encodes only a specific set of metadata fields related to proc macros, everything else is empty.
It wasn't always like that, so decoder still has many is_proc_macro conditions.
We should generally cleanup it and remove them. But I guess they can be replaced with asserts instead, that would be more reliable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like we are not checking the is_proc_macro property in majority of cases.
This is how it looks if the asserts are added - petrochenkov@b026841
For Lazy<[T]> it looks like we cannot even check whether it's empty without decoding, that's why some checks are commented out.

So I think we should just drop the is_proc_macro checks without adding asserts, and assume that encoder encodes everything correctly.

Copy link
Member

Choose a reason for hiding this comment

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

For Lazy<[T]> it looks like we cannot even check whether it's empty without decoding, that's why some checks are commented out.

I think you can check the .meta field on a Lazy<[T]>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see.
IMO, it's still simpler to assume that we are just decoding whatever the encoder put there, and make the decoder "fast and dumb", I've updated the PR description.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with not adding any of the asserts too, if we are sufficiently confident lack of them will not really cause any issues. Just wanted to make sure we at least considered it.

Also remove unnecessary `is_proc_macro_crate` checks from decoder
@nagisa
Copy link
Member

nagisa commented Jan 16, 2022

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Jan 16, 2022

📌 Commit 4549b13 has been approved by nagisa

@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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2022
@bors
Copy link
Contributor

bors commented Jan 16, 2022

⌛ Testing commit 4549b13 with merge 48e89b0...

@bors
Copy link
Contributor

bors commented Jan 16, 2022

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 48e89b0 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 16, 2022
@bors bors merged commit 48e89b0 into rust-lang:master Jan 16, 2022
@rustbot rustbot added this to the 1.60.0 milestone Jan 16, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (48e89b0): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

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. 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