-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add an unstable --output-format
option to cargo rustdoc
#12103
Comments
It might be good to list all the concerns that need to be considered for this. For example:
Overall seems like a reasonable flag to add to me. |
@obi1kenobi since you rely on rustdoc's output format, I'm curious on your thoughts on this issue. |
Thanks for raising those points @ehuss, I'll try to address them based on what I know.
I don't think it's necessary to return an error, at least for the JSON format.
I'm not familiar with the feature, nor with its implications for the JSON format. @aDotInTheVoid perhaps?
Yes, adding it to I have limited this issue to |
Thanks for the ping @epage. I'm strongly in favor of this. It's a reasonable feature to have, and from my perspective, improving the rustdoc JSON cache hit rate is extremely worth it. Thanks to @LukeMathWalker for figuring this out. Anything that improves rustdoc JSON performance would be hugely impactful for cargo-semver-checks, since that's by far the "long pole" in its perf graph right now. For context, cargo-semver-checks v0.20 shipped a massive perf improvement: 109x faster checking time in tokio, 2354x in Since we've significantly reduced the time taken by all the other steps, the "current" version's rustdoc JSON generation is easily 70-80% of cargo-semver-checks wall-clock time right now. In turn, our users report that
This is ever so slightly imprecise, the filename is the lib target's name with all
I believe the JSON does not have an ability to include examples. It only includes doc comments that are explicitly set on items. For the time being, scraping can be disabled. I have no opinion at the moment on whether rustdoc JSON should include examples, and I think it's fine to decide on that later since the JSON format is unstable anyway.
I'm fine with attempting to open the JSON file with the user's default viewer (mine would be VSCode), falling back to the browser if no default viewer is available. If this is complex to achieve on day 1, I'm also fine with this being an error for now.
Totally fine with adding it there too, it makes sense to me. |
This PR is mostly the result of a few "instrument, measure, optimise" cycles, looking to understand where `pavex_cli` spends its time when generating application code. As it turns out, with a warm cache, the vast majority of the time is spent computing the JSON docs for the local crates. As it stands, this is not something that we can optimise on our own. We have two options, which both require upstream work: 1. Make the JSON docs generation faster; 2. Compute multiple JSON docs in parallel (up to the number of threads available on the machine). I don't have any concrete leads on 1., while 2. depends on adding `--output-format` support to `cargo doc`. See rust-lang/cargo#12103 While hunting inefficiencies down, I added instrumentation around the key steps of the compiler as well as enriched the `--debug` option with a disk-based output that can be loaded in the Chrome tracing viewer (chrome://tracing or ui.perfetto.dev). You get this kind of visualisation: <img width="1242" alt="immagine" src="https://github.com/LukeMathWalker/pavex/assets/20745048/bd5381c3-d1db-48ce-9b59-eadb956ff4a3"> This is an execution trace with a warm cache. You can clearly see how the lion share of the execution time it spend in `_compute_crate_docs`. Miscellaneous changes: - Re-added the `realworld` scaffolding in the `examples` folder; - The package graph and the SQLite connection are now created in parallel. We save ~10ms on the overall execution time.
Is there any concern here that remains to be addressed? Or should we start sketching the implementation? |
Most concerns seem to be answered. I got some minor questions here: How stable is the rustdoc JSON output? Does it make sense that a user wants to keep different versions of JSON output at the same time? Apart from my trivial questions, I feel like the flag isn't something that cannot be rolled back, and It also won't affect major build workflow of Cargo. Thus I am happy to discuss the design and implementation. |
It is versioned (via the |
Let's do a quick poll before starting. @rfcbot fcp merge Proposed solution
|
Team member @weihanglo has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
So long as this is unstable, I have no concern with this. Once we have it,. it'll then also make it easier to explore the benefits and challenges with making it stable (assuming the rustdoc flag is stable) |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
There is no need to wait util FCP ends. People interested in doing it can start. The Cargo Team may not have a large capacity to mentor but for the review part we'll try our best. |
I'll get started next week then 👍🏻 Thanks! |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Hi @LukeMathWalker , were you able to start working on this? |
No, a few other things had to take priority. |
Can other folks(including me) give it a try? Else I believe it's better to assign it to yourself. |
If you have the time to start on it immediately, go ahead 😁 |
@rustbot claim |
We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format` Fixes rust-lang#12103 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format` Fixes rust-lang#12103 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format` Fixes rust-lang#12103 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format` Fixes rust-lang#12103 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format` Fixes rust-lang#12103 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format` Fixes rust-lang#12103 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format` Fixes rust-lang#12103 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
Add unstable `--output-format` option to `cargo rustdoc` Add unstable `--output-format` option to "rustdoc" We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * A new field `json` in `CompileMode::Doc`. * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format=json` Fixes #12103
@obi1kenobi @LukeMathWalker |
We achieved this by: * Handle `--output-format` argument, accepting `html` or `json` * If `json` is passed, we append the following in `prepare_rustdoc`: 1. `-Zunstable-options` 2. `--output-format` Fixes rust-lang#12103 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
Problem
rustdoc
(on nightly) exposes an--output-format
option to choose the format of the generated documentation: either HTML (the default) or JSON (the new unstable backend).If you choose the JSON format, the output file of the unit is no longer
/target/doc/<crate_name>/index.html
; it becomes/target/doc/<crate name>.json
.Since there is no way to specify the output format as an option of
cargo rustdoc
itself,cargo
assumes that the only possible output path for a doc unit is the HTML one. As a consequence, the JSON output is never considered "fresh" and we miss out on caching (see the test case in #12100, which fails onmaster
).Proposed Solution
Since
cargo
must remain unaware of the semantics ofrustdoc
's extra arguments, I suggest we add--output-format
as an unstablecargo rustdoc
argument, mimicking the semantics of the underlying--output-format
option forrustdoc
.This would allow
cargo
to reason about it and take it into account in the fingerprinting logic.Notes
No response
The text was updated successfully, but these errors were encountered: