Skip to content

[rustdoc] Display total time and compilation time of merged doctests #144308

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

Merged
merged 2 commits into from
Jul 30, 2025

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Jul 22, 2025

Fixes #144270.

Does it look good to you @kpreid?

image

@rustbot
Copy link
Collaborator

rustbot commented Jul 22, 2025

r? @notriddle

rustbot has assigned @notriddle.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

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

kpreid commented Jul 22, 2025

Does it look good to you @kpreid?

This seems sufficient, in that it communicates the missing information, separately.

However, there is a way in which I predict it will be frequently confusing: there is no spatial or textual association of "merged doctests compilation took…" with which tests are the merged ones. A user wanting to know which doctests this refers to has to reason about what 'merged doctests' means and then, using that fact, figure out they must be the first group since the second group has compile-fail tests.

I strongly recommend that the report of compilation time should not be separated from the tests it refers to by unrelated tests.

When I initially imagined quickly adding this feature, I imagined putting the doctest compilation time at the top, corresponding to when it actually happens, and thus also adjacent to the merged tests. Another option would be to label the group of merged tests as merged, somehow.

@GuillaumeGomez
Copy link
Member Author

You can have multiple merged doctests groups, so unless we show it for each group, I'm not sure it's really useful. It tells how much time it spent compiling merged doctests and the total time for all doctests.

@kpreid
Copy link
Contributor

kpreid commented Jul 22, 2025

Ah, I see, I wasn't aware that there was a possibility of multiple groups. I don't have any further ideas. Thank you for working on this.

Comment on lines 62 to 82
fn display_times(&self) {
// If no merged doctest was compiled, then there is nothing to display.
if self.added_compilation_times > 0 {
println!("{self}");
}
}
}

impl fmt::Display for MergedDoctestTimes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"all doctests ran in {:.2}s; merged doctests compilation took {:.2}s",
self.total_time.elapsed().as_secs_f64(),
self.compilation_time.as_secs_f64(),
)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we still print the total compilation time, even if there are no merged doctests?

Copy link
Member Author

Choose a reason for hiding this comment

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

No because in this case, the numbers displayed by libtest are already accurate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Some extra info: for standalone tests, libtest reports both compilation and run time as each doctest passed to libtest will call the doctest_run_fn which handles both.

Copy link
Contributor

Choose a reason for hiding this comment

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

hm, that's odd, that's what i thought initially, but the numbers in the screenshot simply don't add up for that to be the case. not sure what's happening here.

Copy link
Contributor

@lolbinarycat lolbinarycat Jul 23, 2025

Choose a reason for hiding this comment

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

in any case, the comment explaining the rationale for ommitting all the output seems incomplete and mildly misleading.

Copy link
Member Author

Choose a reason for hiding this comment

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

So calculation is:

merged compilation times + standalone run times + merged run times = total time

With the screenshot numbers:

1.24 + 0.43 + 0.05 = 1.72

That seems to match the numbers. Did I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, i see it now, i wasn't looking at the top section because i've never seen the output for a crate with both standalone and merged doctests, and i didn't expect then to be printed in seperate groups.

i'm not sure if the output is confusing or it's just me, but maybe if the time taken for merged doctest compilation was printed right before the merged doctests were run, that would be more intuitive, saying the times for things as they happen?

i would say we should just add a comment somewhere, but that won't make it more intuitive for users..

but maybe making this 10% more intuitive isn't worth the extra implement effort, i don't know how hard it would be to print things in that order.

another possibility is when it says "running N tests" make it say "running N merged doctests" or "running N standalone doctests" so its more obvious what number refers to what.

Copy link
Member Author

Choose a reason for hiding this comment

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

i'm not sure if the output is confusing or it's just me, but maybe if the time taken for merged doctest compilation was printed right before the merged doctests were run, that would be more intuitive, saying the times for things as they happen?

What happens if the merged doctests compilation failed then? We still need to show this number but then it's followed by standalone doctests. Seems even more confusing imo.

Putting this information at the end sounds the less confusing option to me.

another possibility is when it says "running N tests" make it say "running N merged doctests" or "running N standalone doctests" so its more obvious what number refers to what.

Sounds like an improvement that can be sent as a follow-up.

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the merged doctests compilation failed then? We still need to show this number but then it's followed by standalone doctests. Seems even more confusing imo.

I don't know why it would be printed before the standalone tests instead of after them, but I'll trust that there's some implementation detail I don't know of.

Sounds like an improvement that can be sent as a follow-up.

Sounds good!

Copy link
Member Author

Choose a reason for hiding this comment

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

What happens if the merged doctests compilation failed then? We still need to show this number but then it's followed by standalone doctests. Seems even more confusing imo.

I don't know why it would be printed before the standalone tests instead of after them, but I'll trust that there's some implementation detail I don't know of.

This is nothing about technical details, just me trying to underlying that multiplying output is never desirable because of different potential cases. Your starting point was that the current output could be confusing and suggesting some alternatives. And I replied on the suggested alternative, with an example where we might display information about compile time for merged doctests that actually don't appear anywhere (because the compilation failed, reverting them to standalone doctests).

Anyway, even if not perfect, I think the current display is a nice first step.

@@ -1071,7 +1120,7 @@ fn doctest_run_fn(
no_run: scraped_test.no_run(&rustdoc_options),
merged_test_code: None,
};
let res =
let (_, res) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we're not also tracking this, so we can report (time compiling standalone tests, time compiling merged tests)?

I believe doctests are run with some level of parallelism, so currently we would be reporting the total absolute wall clock time for the total compilation time, but for merged doctests, we're reporting the sum of the amount of time each thread spent compiling. This inconsistency could over-report the impact of merged doctests.

Also, if parallelism is involved, then I think perhaps a more useful metric for minimizing compilation time would be how long the longest test took.

Copy link
Member Author

Choose a reason for hiding this comment

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

We only compile and run standalone tests in parallel, merged doctests are never compiled in parallel (but still run in parallel).

We report raw numbers. Also we cannot get which tests took the longest to run as only libtest has this information in theory (but they don't keep track of it). Finally, I don't see how this is an issue to say how much time was spent in compiling merged doctests.

@GuillaumeGomez
Copy link
Member Author

@bors r=lolbinarycat rollup

@bors
Copy link
Collaborator

bors commented Jul 30, 2025

📌 Commit 64e3078 has been approved by lolbinarycat

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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2025
bors added a commit that referenced this pull request Jul 30, 2025
Rollup of 4 pull requests

Successful merges:

 - #143465 (Support multiple crate versions in --extern-html-root-url)
 - #144308 ([rustdoc] Display total time and compilation time of merged doctests)
 - #144655 (clean up codegen fn attrs)
 - #144675 (Reject running `compiletest` self-tests against stage 0 rustc unless explicitly allowed)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 61760fb into rust-lang:master Jul 30, 2025
10 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 30, 2025
rust-timer added a commit that referenced this pull request Jul 30, 2025
Rollup merge of #144308 - GuillaumeGomez:merged-doctest-times, r=lolbinarycat

[rustdoc] Display total time and compilation time of merged doctests

Fixes #144270.

Does it look good to you `@kpreid?`

<img width="908" height="263" alt="image" src="https://github.com/user-attachments/assets/cd5d082d-c4e0-42ed-91dd-bd263b413dcd" />
@GuillaumeGomez GuillaumeGomez deleted the merged-doctest-times branch July 31, 2025 09:01
@arpadav
Copy link

arpadav commented Aug 1, 2025

@GuillaumeGomez this is breaks the --format json unstable option, since the time displayed goes to stdout. as a result, if you run something like:

cargo +nightly test --doc -- -Z unstable-options --format json > doc-test.json

then

...
{ "type": "suite", "event": "ok", "passed": 0, "failed": 0, "ignored": 5, "measured": 0, "filtered_out": 0, "exec_time": 0.000229133 }
all doctests ran in 0.17s; merged doctests compilation took 0.17s

this line is at the end of each output. in addition, when using the --workspace flag, it appears after every library is doc-tested.

I assume this is not intended? It can easily be dealt with, but I realized my CICD started failing when parsing this output so I wanted to ask/report

@GuillaumeGomez
Copy link
Member Author

No indeed. Please open an issue and ping me on it. I'll take a look in the next days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Doctest execution should report discovery and compilation time
7 participants