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: Only store locations in Cache::extern_locations and calculate the other info on-demand #84601

Merged

Conversation

tdelabro
Copy link
Contributor

help #84588

@rust-highfive
Copy link
Collaborator

r? @ollie27

(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 Apr 26, 2021
@tdelabro
Copy link
Contributor Author

r? @jyn514

@rust-highfive rust-highfive assigned jyn514 and unassigned ollie27 Apr 26, 2021
@tdelabro
Copy link
Contributor Author

tdelabro commented Apr 26, 2021

Hey @jyn514, can I store extern_html_root_url as a new field of Cache, instead of the whole extern_locations HashMap ?

Or is there a way for me to access it a any time via the context. I feel like this is not possible because I would need the DocContext as in:

rust/src/librustdoc/core.rs

Lines 561 to 565 in 154858c

let render_options = ctxt.render_options;
let mut cache = ctxt.cache;
krate = tcx.sess.time("create_format_cache", || {
cache.populate(krate, tcx, &render_options.extern_html_root_urls, &render_options.output)
});

@jyn514
Copy link
Member

jyn514 commented Apr 26, 2021

can I store extern_html_root_url as a new field of Cache, instead of the whole extern_locations HashMap ?

Yes, that's fine :) render_options is kind of a mess, I would rather we keep more things on Cache anyway.

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-cleanup Category: PRs that clean code up or issues documenting cleanup. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. labels Apr 26, 2021
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

I think the rest of this is still in progress, right? Feel free to ping me when this is ready for review.

src/librustdoc/clean/types.rs Show resolved Hide resolved
@bors

This comment has been minimized.

@jyn514 jyn514 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 Apr 28, 2021
@tdelabro tdelabro force-pushed the rustdoc-get-rid-of-cache-extern_locations branch 2 times, most recently from f00355c to 7417c70 Compare April 28, 2021 21:55
@tdelabro
Copy link
Contributor Author

tdelabro commented Apr 29, 2021

I have been able to replace all the usages of Cache::extern_locations by some on-demand computation, except for two of them, in src/librustdoc/html/format.rs, in the functions href and primitive_link. When I try to do so errors arise when running test/rustdoc, for tests such as issue-15318.rs.

My on-demand computation return Some(ExternalLocation::Local) while the value stored in the cache is ExternalLocation::Remote("http://example.com").
The reason why this happen is that, while the arguments passed to the function location are the same, the output change because the computer file system state has changed between those two calls.

I printed some debug inside the location function:

        debug!(?local_location, ?self.crate_num, ?extern_url, ?dst);
        debug!("{}", local_location.is_dir())

Here is the output for the call that fill the cache (inside rustdoc::formats::cache::Cache::populate):

DEBUG rustdoc::clean::types local_location="/Users/timothee/Documents/rust/build/x86_64-apple-darwin/test/rustdoc/issue-15318/issue_15318", self.crate_num=crate4, extern_url=None, dst="/Users/timothee/Documents/rust/build/x86_64-apple-darwin/test/rustdoc/issue-15318"
DEBUG rustdoc::clean::types false

And here is the output for the on-demand call (inside `rustdoc::html::format::primitive_link):

DEBUG rustdoc::clean::types local_location="/Users/timothee/Documents/rust/build/x86_64-apple-darwin/test/rustdoc/issue-15318/issue_15318", self.crate_num=crate4, extern_url=None, dst="/Users/timothee/Documents/rust/build/x86_64-apple-darwin/test/rustdoc/issue-15318"
DEBUG rustdoc::clean::types true

The arguments are the same but in the on-demand call we enter the following branch:

        if local_location.is_dir() {
            return Local;
        }

So my issue seem to be that a new directory have been created been created at /rust/build/x86_64-apple-darwin/test/rustdoc/issue-15318/issue_15318 while building the documentation. Which seems legit, I suppose creating those directories and files is ultimately the goal of building documentation, but cause some trouble here.

Do you see any way we can get out of this situation ? Maybe slightly postponing the directory creation ?

@jyn514
Copy link
Member

jyn514 commented Apr 29, 2021

Maybe slightly postponing the directory creation ?

I don't think this can work because these href() calls happen while rustdoc is writing the HTML files themselves to disk. What we could do instead is generate files to a temporary directory, then rename them all, something like this:

.
├── old_crate
└── tmp-build
    ├── new_crate1
    └── new_crate2

That will only do as many renames as there are crates, so it shouldn't be much slower - on most file systems, directory renames are basically free as long as they happen on the same filesystem.

That's a fairly large change, so it may be easier in the meantime to only remove name and src_root from the extern_locations map, and still calculate the ExternLocations themselves on-demand. That should still get most of the benefit.

@tdelabro tdelabro force-pushed the rustdoc-get-rid-of-cache-extern_locations branch from 7417c70 to b1ab5cf Compare April 29, 2021 17:16
@jyn514 jyn514 changed the title rustdoc: Get rid of Cache::extern_locations and calculate the info on-demand rustdoc: Only store locations in Cache::extern_locations and calculate the other info on-demand Apr 29, 2021
@tdelabro tdelabro marked this pull request as ready for review April 29, 2021 17:33
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

This looks great :) just want to do a perf run first.

src/librustdoc/clean/types.rs Show resolved Hide resolved
@jyn514
Copy link
Member

jyn514 commented Apr 29, 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 Apr 29, 2021
@bors
Copy link
Contributor

bors commented Apr 29, 2021

⌛ Trying commit b1ab5cf9f3f2fbfef892327240c28e94011b2d10 with merge 327229fc2f1d5d7595a5edd2bbfaf553d7397b38...

@tdelabro tdelabro force-pushed the rustdoc-get-rid-of-cache-extern_locations branch from b1ab5cf to 2cc2639 Compare April 29, 2021 17:46
@jyn514
Copy link
Member

jyn514 commented Apr 30, 2021

@rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

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

@jyn514
Copy link
Member

jyn514 commented Apr 30, 2021

@rust-timer queue b1ab5cf9f3f2fbfef892327240c28e94011b2d10

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

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

@jyn514
Copy link
Member

jyn514 commented Apr 30, 2021

@bors try @rust-timer queue include=-doc

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

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

@bors
Copy link
Contributor

bors commented Apr 30, 2021

⌛ Trying commit 2cc2639 with merge e5668a2fb8fd709b737433c50a467ea877ab5f4b...

@bors
Copy link
Contributor

bors commented Apr 30, 2021

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

@rust-timer
Copy link
Collaborator

Queued e5668a2fb8fd709b737433c50a467ea877ab5f4b with parent a45f0d7, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (e5668a2fb8fd709b737433c50a467ea877ab5f4b): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

@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. labels Apr 30, 2021
@jyn514
Copy link
Member

jyn514 commented Apr 30, 2021

Both perf and max-rss look like noise, but this is a nice cleanup :)

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 30, 2021

📌 Commit 2cc2639 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-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 30, 2021
@jyn514
Copy link
Member

jyn514 commented Apr 30, 2021

Also, given how little perf impact there was, I wouldn't spend too much time on my idea in #84601 (comment) - shrinking doctree::Module or something like that might be more helpful.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Apr 30, 2021
…xtern_locations, r=jyn514

rustdoc: Only store locations in Cache::extern_locations and calculate the other info on-demand

 help rust-lang#84588
JohnTitor added a commit to JohnTitor/rust that referenced this pull request May 1, 2021
…xtern_locations, r=jyn514

rustdoc: Only store locations in Cache::extern_locations and calculate the other info on-demand

 help rust-lang#84588
bors added a commit to rust-lang-ci/rust that referenced this pull request May 1, 2021
Rollup of 8 pull requests

Successful merges:

 - rust-lang#84601 (rustdoc: Only store locations in Cache::extern_locations and calculate the other info on-demand)
 - rust-lang#84704 (platform-support.md: Update for consistency with Target Tier Policy)
 - rust-lang#84724 (Replace llvm::sys::fs::F_None with llvm::sys::fs::OF_None)
 - rust-lang#84740 (Reset the docs' copy path button after 1 second)
 - rust-lang#84749 (Sync `rustc_codegen_cranelift`)
 - rust-lang#84756 (Add a ToC to the Target Tier Policy documentation)
 - rust-lang#84765 (Update cargo)
 - rust-lang#84774 (Fix misspelling)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e30d952 into rust-lang:master May 1, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. 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.

8 participants