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

Rustdoc: use is_doc_hidden method on more places #92227

Merged
merged 1 commit into from
Dec 25, 2021

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Dec 23, 2021

While profiling rustdoc, I noticed that finding out if some item is marked with #[doc(hidden)] is relatively hot, so I tried to optimize it.

I noticed that there is already a method called is_doc_hidden on TyCtxt, but it wasn't used much, so I replaced the manual calls to attrs(...).has_word(...) with this method. Just by doing that, perf. was improved locally, although I'm not sure if the semantics of the previous calls and this method are the same?

As another step, I tried to querify is_doc_hidden, but I didn't include that here until we see the perf. results from the first commit and until I find whether this change is OK at all :)

Can I ask for a perf. run? Thanks.

r? @jyn514

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 23, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 23, 2021
@jyn514
Copy link
Member

jyn514 commented Dec 23, 2021

I'm on vacation.

r? rust-lang/rustdoc

@jyn514
Copy link
Member

jyn514 commented Dec 23, 2021

@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 23, 2021
@bors
Copy link
Collaborator

bors commented Dec 23, 2021

⌛ Trying commit 0ec3199 with merge 7ea1327e5dec6e8f28c44c1c1da52418eec8055e...

@bors
Copy link
Collaborator

bors commented Dec 23, 2021

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

@rust-timer
Copy link
Collaborator

Queued 7ea1327e5dec6e8f28c44c1c1da52418eec8055e with parent 489296d, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7ea1327e5dec6e8f28c44c1c1da52418eec8055e): comparison url.

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

  • Very large improvement in instruction counts (up to -9.4% on full 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.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 23, 2021
@Kobzol
Copy link
Contributor Author

Kobzol commented Dec 23, 2021

Wow, that seems nice. It could have been caused by missed inlining, because before it was going through a trait, and it was probably making some additional copies. I wonder if it's even worth it to cache the result now.

But I'm still not if this is correct :)

@jyn514 jyn514 added the I-compiletime Issue: Problems and improvements with respect to compile times. label Dec 23, 2021
@jyn514
Copy link
Member

jyn514 commented Dec 23, 2021

I wonder if it's even worth it to cache the result now.

The compiler already caches query executions, please don't add more layers on top.

@Kobzol
Copy link
Contributor Author

Kobzol commented Dec 23, 2021

But is_doc_hidden is not currently a query, right? Or is it? I thought that it's just a regular method on TyCtxt.

@jyn514
Copy link
Member

jyn514 commented Dec 23, 2021

Yes, you're right, it's just a regular method. I would leave it as is for now, it doesn't seem particularly expensive to calculate. If you're interested in making it a query that can go in a new PR.

@jyn514
Copy link
Member

jyn514 commented Dec 25, 2021

@bors r+

Great find!

@bors
Copy link
Collaborator

bors commented Dec 25, 2021

📌 Commit 0ec3199 has been approved by jyn514

@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 Dec 25, 2021
@bors
Copy link
Collaborator

bors commented Dec 25, 2021

⌛ Testing commit 0ec3199 with merge c096176...

@bors
Copy link
Collaborator

bors commented Dec 25, 2021

☀️ Test successful - checks-actions
Approved by: jyn514
Pushing c096176 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 25, 2021
@bors bors merged commit c096176 into rust-lang:master Dec 25, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 25, 2021
@Kobzol Kobzol deleted the rustdoc-doc-hidden branch December 25, 2021 18:09
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c096176): comparison url.

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

  • Very large improvement in instruction counts (up to -9.3% on full builds of helloworld)
  • Moderate regression in instruction counts (up to 1.2% on incr-unchanged builds of deeply-nested-async)

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

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

@rustbot rustbot added the perf-regression Performance regression. label Dec 25, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 1, 2022
…Gomez

Add Attribute::meta_kind

The `AttrItem::meta` function is being called on a lot of places, however almost always the caller is only interested in the `kind` of the result `MetaItem`. Before, the `path`  had to be cloned in order to get the kind, now it does not have to be.

There is a larger related "problem". In a lot of places, something wants to know contents of attributes. This is accessed through `Attribute::meta_item_list`, which calls `AttrItem::meta` (now `AttrItem::meta_kind`), among other methods. When this function is called, the meta item list has to be recreated from scratch. Everytime something asks a simple question (like is this item/list of attributes `#[doc(hidden)]`?), the tokens of the attribute(s) are cloned, parsed and the results are allocated on the heap. That seems really unnecessary. What would be the best way to cache this? Turn `meta_item_list` into a query perhaps? Related PR: rust-lang#92227

r? rust-lang/rustdoc
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 25, 2022
…eGomez

Rustdoc: remove ListAttributesIter and use impl Iterator instead

This is a continuation of rust-lang#92227.

I found that `ListAttributesIter` did not optimize well and replacing it with a simple `impl Iterator` resulted in 1-3 % instruction count wins locally.

Because I needed to use `impl Iterator` on a slice of AST attributes, I had to implement it using GAT + impl trait. I also have a version without GAT [here](Kobzol@5470e2a), if GATs are not welcome in rustdoc :D Locally it resulted in equal performance numbers.

Can I ask for a perf. run? Thanks.

r? rust-lang/rustdoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-compiletime Issue: Problems and improvements with respect to compile times. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants