-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
Conversation
r? @notriddle rustbot has assigned @notriddle. Use |
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. |
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. |
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. |
src/librustdoc/doctest.rs
Outdated
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(), | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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) = |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
a3d520c
to
d0ec770
Compare
d0ec770
to
64e3078
Compare
@bors r=lolbinarycat rollup |
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
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 this is breaks the 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 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 |
No indeed. Please open an issue and ping me on it. I'll take a look in the next days. |
Fixes #144270.
Does it look good to you @kpreid?