-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Sort tests at compile time, not at startup #99939
Conversation
r? @fee1-dead (rust-highfive has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
LGTM, and good call. Any time we can move logic that runs unconditionally at startup to compile time, that's a win. |
// pretty-mode:expanded | ||
// pp-exact:tests-are-sorted.pp | ||
|
||
extern crate test; |
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.
Are we really generating a fresh extern crate test before every #[test]
? That seems odd.
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.
There is a lot around these changes which seems odd to me.
This seems like it will affect all users of libtest, correct? |
Yes, it is possible for other users of libtest to notice. Personally I feel we are well within our rights to change this, because the sorting is not documented anywhere that I can find and this is also behind an unstable feature. But I do sympathize with users who have come to treat things under |
I think we should try to cover the easily known use cases (e.g., compiletest, compiletest-rs) with patches or PRs, since those affect CI & folks developing in tree immediately. Beyond that, I think we can also consider whether keeping the sort at runtime is that costly - I think our default sort has "already sorted" detection, maybe that's fast enough to not worry here? It wouldn't be too hard to detect an unsorted input and print a warning (temporarily, we could remove that in ~4 weeks or something). But I also don't feel we have to do this - I think so long as we fix compiletest{,-rs}, that's okay, and we can also open an issue and pin it so if folks come looking hopefully it's an easy thing to spot. Happy to pin something if you'd like to draft a short note. |
I'm adding a commit for
Unfortunately no. I did think of this initially, but it only brings us down from 4 minutes sorting the tests to 3 minutes. The slowness of Miri is in general super-linear; even if the already-sorted case is a fast path for Rust compiled with LLVM, it's entirely possible that the "fast path" is the slow part of the sorting algorithm under Miri. This is all wobbly and complicated, which is why I'm keen on this change to when we do the sort because it just removes the code path entirely. |
Can we do something with |
We could. But I'm not sure that is a good idea, the whole point of Miri is to check for errors in code, so if we're running different code in Miri and outside of Miri, you could start to wonder what the point of the tool is. And new users are already sometimes suspicious of Miri's claims that their code is UB, I don't want to make understanding it any harder than it already is. I'm willing to be convinced otherwise, but I think changing semantics of code with a |
Reassigning this because I am not familiar with the code to approve. r? rust-lang/compiler |
I think the next step here is probably to treat this as a change to an unstable libs API and file an ACP (https://std-dev-guide.rust-lang.org/feature-lifecycle/api-change-proposals.html), presuming that geta accepted I'd be comfortable moving ahead here with a pinned issue about this change. |
@Mark-Simulacrum, do you want to take this? |
@rustbot label +I-libs-api-nominated |
@rustbot label -I-libs-api-nominated |
Libs side looks fine to me, but it's mostly a compiler change. Can someone review those changes? r? compiler |
@bors r=thomcc,jackh726 |
…ackh726 Sort tests at compile time, not at startup Recently, another Miri user was trying to run `cargo miri test` on the crate `iced-x86` with `--features=code_asm,mvex`. This configuration has a startup time of ~18 minutes. That's ~18 minutes before any tests even start to run. The fact that this crate has over 26,000 tests and Miri is slow makes a lot of code which is otherwise a bit sloppy but fine into a huge runtime issue. Sorting the tests when the test harness is created instead of at startup time knocks just under 4 minutes out of those ~18 minutes. I have ways to remove most of the rest of the startup time, but this change requires coordinating changes of both the compiler and libtest, so I'm sending it separately. (except for doctests, because there is no compile-time harness)
Rollup of 7 pull requests Successful merges: - rust-lang#99578 (Remove redundant lifetime bound from `impl Borrow for Cow`) - rust-lang#99939 (Sort tests at compile time, not at startup) - rust-lang#102271 (Stabilize `duration_checked_float`) - rust-lang#102766 (Don't link to `libresolv` in libstd on Darwin) - rust-lang#103277 (Update libstd's libc to 0.2.135 (to make `libstd` no longer pull in `libiconv.dylib` on Darwin)) - rust-lang#103437 (Sync rustc_codegen_cranelift) - rust-lang#103466 (Fix grammar in docs for std::io::Read) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Do fewer passes and generally be more efficient when filtering tests Follow-on of the work I started with this PR: rust-lang#99939 Basically, the startup code for libtest is really inefficient, but that's not usually a problem because it is distributed in release and workloads are small. But under Miri which can be 100x slower than a debug build, these inefficiencies explode. Most of the diff here is making test filtering single-pass. There are a few other small optimizations as well, but they are more straightforward. With this PR, the startup time of the `iced` tests with `--features=code_asm,mvex` drops from 17 to 2 minutes (I think Miri has gotten slower under this workload since rust-lang#99939). The easiest way to try this out is to set `MIRI_LIB_SRC` to a checkout of this branch when running `cargo +nightly miri test --features=code_asm,mvex`. r? `@thomcc`
Do fewer passes and generally be more efficient when filtering tests Follow-on of the work I started with this PR: rust-lang/rust#99939 Basically, the startup code for libtest is really inefficient, but that's not usually a problem because it is distributed in release and workloads are small. But under Miri which can be 100x slower than a debug build, these inefficiencies explode. Most of the diff here is making test filtering single-pass. There are a few other small optimizations as well, but they are more straightforward. With this PR, the startup time of the `iced` tests with `--features=code_asm,mvex` drops from 17 to 2 minutes (I think Miri has gotten slower under this workload since #99939). The easiest way to try this out is to set `MIRI_LIB_SRC` to a checkout of this branch when running `cargo +nightly miri test --features=code_asm,mvex`. r? `@thomcc`
Do fewer passes and generally be more efficient when filtering tests Follow-on of the work I started with this PR: rust-lang/rust#99939 Basically, the startup code for libtest is really inefficient, but that's not usually a problem because it is distributed in release and workloads are small. But under Miri which can be 100x slower than a debug build, these inefficiencies explode. Most of the diff here is making test filtering single-pass. There are a few other small optimizations as well, but they are more straightforward. With this PR, the startup time of the `iced` tests with `--features=code_asm,mvex` drops from 17 to 2 minutes (I think Miri has gotten slower under this workload since #99939). The easiest way to try this out is to set `MIRI_LIB_SRC` to a checkout of this branch when running `cargo +nightly miri test --features=code_asm,mvex`. r? `@thomcc`
Recently, another Miri user was trying to run
cargo miri test
on the crateiced-x86
with--features=code_asm,mvex
. This configuration has a startup time of ~18 minutes. That's ~18 minutes before any tests even start to run. The fact that this crate has over 26,000 tests and Miri is slow makes a lot of code which is otherwise a bit sloppy but fine into a huge runtime issue.Sorting the tests when the test harness is created instead of at startup time knocks just under 4 minutes out of those ~18 minutes. I have ways to remove most of the rest of the startup time, but this change requires coordinating changes of both the compiler and libtest, so I'm sending it separately.
(except for doctests, because there is no compile-time harness)