Rust: Middle size, 80 000 lines, project but very slow, 5 hours, compilation

Created on 5 Oct 2019  ·  11Comments  ·  Source: rust-lang/rust

This code is the MAVLink  protocol handler, and generated by one of the MAVLink specification. It is  C/Rust  mixed project, so to compile it you will need  RustCC  an any  C  compiler.

To check how slow  rustc  is, check this out , and run  cargo test  in the  GroundControl/demo  dir

Exactly this project is compiled with error, cause the borrow checker complains in one place.

But anyway, the problem is that compilation is unacceptably slow.

Description

/GroundControl/lib   generated API

/GroundControl/demo/src/use_case  is generated sample of using generated API

/GroundControl/demo/src/test  the test

I generate variation of this project, with same functionality, in C, C++, C#.... They are the compiled in seconds !

What wrong with my Rust project? How can I speed up compilation?

My PC

Intel I7-7700K

RAM 32G

SSD Samsung 970 PRO

cargo -V

cargo 1.39.0-nightly (ab6fa8908 2019-09-25)

rustc -V

rustc 1.40.0-nightly (22bc9e1d9 2019-09-30)

C-bug E-needs-test I-compiletime T-compiler

Most helpful comment

I've looked into this code and likely found the problem.

The bright side: it compiles in under half a minute if the errors are removed.

The part of the code causing this problem is a test function that tries to test everything at once and has about 8000 lines. The function contains (as of commit ee653b1a0170) 76 borrow checker errors and the part that takes 5 hours is generating the 3-point errors for them. The time is dominated by the repeated recalculation of dominators for the function body.

All 11 comments

Please provide build instructions for that code. Running cargo build in GroundControl/lib gives:
fatal error: ../config.h: No such file or directory.

GroundControl/lib gives: gives:.....

But I wrote

and run cargo test in the GroundControl/demo dir

That gives the same error, since it just has a dependency on the crate in lib...

Small bug fix in the build.rs file.
Please try again.
Thanks.

That didn't fix it

made more platform specific fixes.
check now please.

I've looked into this code and likely found the problem.

The bright side: it compiles in under half a minute if the errors are removed.

The part of the code causing this problem is a test function that tries to test everything at once and has about 8000 lines. The function contains (as of commit ee653b1a0170) 76 borrow checker errors and the part that takes 5 hours is generating the 3-point errors for them. The time is dominated by the repeated recalculation of dominators for the function body.

A minimized reproduction looks like this

fn get_pair(_a: &mut u32, _b: &mut u32) {
}

macro_rules! x10 {
    ($($t:tt)*) => {
        $($t)* $($t)* $($t)* $($t)* $($t)*
        $($t)* $($t)* $($t)* $($t)* $($t)*
    }
}

#[allow(unused_assignments)]
fn main() {
    let mut x = 1;

    get_pair(&mut x, &mut x);

    x10!{ x10!{ x10!{ if x > 0 { x += 2 } else { x += 1 } } } }
}

On my laptop this code requires about 25 seconds to print the error for the 1000 if statements generated above and scales with the cube of the statement count.

On the bright side, waiting 5 hours for borrowck errors is still faster than trying to debug a memory corruption in a language without borrowck. 😜

(edit: lol, why so serious, this was meant to be humorous and not a complaint about Rust…)

Thanks to @cheblin for the report and helping us to work with it, and to @tanriol for the quick analysis and fix!

Was this page helpful?
0 / 5 - 0 ratings