-
Notifications
You must be signed in to change notification settings - Fork 46
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
Very long build time #184
Comments
Unfortunately `rstest` uses the standard rust test runner and adding a test
means adding a new `#[test]` function. So we should pay attention when we
use cartesian products....
I think that there is nothing that you can do better than this if you
really want an independent test for each single case....
Il giorno sab 11 mar 2023 alle ore 08:34 Sebastian Meßmer <
***@***.***> ha scritto:
… I added some rstest based parameterized tests to a project, and suddenly
the incremental build time is very long. I just change one line in the
file, but cargo needs 5-10 minutes to incrementally compile it. I had been
planning to add several more tests like this, but build time seems to
linearly grow with it and would quickly be several hours.
Admittedly, this is generating quite a few test cases because of a large
cartesian product of test parameters (32 x 6 x 3 x 3 = 1728 test cases),
but I still wouldn't have expected it to take that long to build.
Particularly troublesome seems to be this test:
https://github.com/cryfs/cryfs/blob/feature/rust/src/blockstore/rust/blobstore/src/on_blocks/data_tree_store/tree.rs#L1306-L1322
Di you know any tips on how I could speed up build times here? For most of
the build time, it only uses a single core so I assumed it would be the
linker, but even using lld or mold doesn't speed it up significantly.
If you want to reproduce, clone the repo and commit linked above and run
"cargo test" from the "src/blockstore/rust/blobstore" directory.
—
Reply to this email directly, view it on GitHub
<#184>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA5Y34JYUHJG6TS367O64LLW3QTJPANCNFSM6AAAAAAVXKUTGU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Thanks for your fast reply. Do you know what it actually is that is taking so much time here? Is it expansion of the I feel like there must be something I can do to ideally speed compile times up, or at least make the compilation process use more than one core. |
I don't think that the macro expansion take too much time (the tokio one is really trivial) but I bet on the linker that should link tons lines of code. To profile the compilation you can take a look at https://rustc-dev-guide.rust-lang.org/profiling.html. Anyway, if the most of the time is spending in the last stage maybe is compile and linking your test code. You can try also this https://rustc-dev-guide.rust-lang.org/parallel-rustc.html but I don't think that it can really help 😢 |
… horrible compile times, see la10736/rstest#184
I investigated a bit more. Looks like it's mostly because
fn test_case_1() {
let body = async {
let ..params.. = ..;
test_func().await
};
#[allow(clippy::expect_used)]
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed building the Runtime")
.block_on(body)
} and I fixed it in my code by using macro_rules! run_tokio_test {
($code:block) => {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(async move {$code});
};
} and then, instead of this #[rstest]
...#[cases]...
#[tokio::test]
async fn my_test(
...#[values]...
) {
... code ...
} do this: #[rstest]
...#[cases]...
#[test]
fn my_test(
...#[values]...
) {
run_tokio_test! ({
... code ...
});
} With this approach, I introduced this macro in this commit and:
While this works for me for now, I think a solution within |
Thank very much for the analysis: it's super useful catch!!! I've tried a generic approach but I should introduce a global hash table .... I'll need to investigate more. |
I did some experiments in https://github.com/la10736/test_in_test but I need to check if there is a better way |
I haven't looked at how |
Ok, you're not so far from how it works but... in the reverse order 😄 . Every procedural macro attribute works on its surrounded code: call the function associated to the attribute with the block's syntax tree that follow the attribute and replace it with the output syntax tree returned. Compiler resolve procedural macros in the order that they are in the code. In this scenario |
Oh I see, the argument point makes sense. How did you solve this in today's rstest? Do you replace Are there test generators that might run multiple tests in parallel on the same thread? Looking at tokio, it seems to use a different threat for each test, so the thread_local (or lazy_static with thread_name) approach could work. Might break with |
No: For each input combination I generate a new The multithreaded case cannot be an issue: every |
Ah I see, you're not actually processing the Looks like your idea should work but it would introduce some overhead. If you're looking for more ideas, here are two that jumped to my mind: Seems to me that one option would be to eagerly expand the Another option could be to keep doing what retest is doing today to keep general support of all test macros, but add a special case optimization for known-expensive ones like |
From the first (and very partial) benchmark seams very negligible.
That was exactly what I'm looking for.... but seams stalled 😢
I thought about it but I'll be my last resource. |
I guess another option could be to fix |
I did some test in https://github.com/la10736/test_in_test and I fond a good implementation with I'll try to implement it in the next days in a branch (I hope tomorrow but I'm not sure). Then you can try it in your codebase. |
Sounds good. Happy to report back with measurements once you have something. |
I was wrong 😢 It's really hard try to encapsulate the state in a generic static object because size can change for every |
… horrible compile times, see la10736/rstest#184
… horrible compile times, see la10736/rstest#184
… horrible compile times, see la10736/rstest#184
Any progress on this? |
No, I'm sorry. I've no time to work on it. |
No worries -- maybe we can help. I'll take a look at the previous work and report back if I get any actionable ideas |
I added some rstest based parameterized tests to a project, and suddenly the incremental build time is very long. I just change one line in the file, but cargo needs 5-10 minutes to incrementally compile it. I had been planning to add several more tests like this, but build time seems to linearly grow with it and would quickly be several hours.
Admittedly, this is generating quite a few test cases because of a large cartesian product of test parameters (32 x 6 x 3 x 3 = 1728 test cases), but I still wouldn't have expected it to take that long to build. Particularly troublesome seems to be this test: https://github.com/cryfs/cryfs/blob/6161c8c89e35892a8c3687cc8f53685b08b2febf/src/blockstore/rust/blobstore/src/on_blocks/data_tree_store/tree.rs#L1306-L1322
Do you know any tips on how I could speed up build times here? I tried:
If you want to reproduce, clone the repo and commit linked above and run "cargo test" from the "src/blockstore/rust/blobstore" directory.
The text was updated successfully, but these errors were encountered: