Skip to content

Excessive rebuilding when nothing changed #3346

Closed

Description

@imotov

Describe the bug
In the last 3 weeks (between 36051bd and the current main branch) something changed that causes cargo to do partial rebuild when it is not really necessary. This is especially noticeable in VSCode on slow machines or while working with containers and trying to execute something on command line.

Steps to reproduce (if applicable)
Steps to reproduce the behavior:

  1. Run the following 3 commands:
cargo clean
cargo build --features=postgres
cargo run --features=postgres -- run --service searcher --service metastore --config ../config/quickwit.yaml

Expected behavior
3 weeks ago the run command started the service immediately. Now it goes through a partial rebuild process that takes minutes on some machine.

Activity

  1. self-assigned this
    on May 16, 2023
  2. trinity-1686a commented on May 16, 2023

    @trinity-1686a
    Contributor

    It might somehow be a compiler regression. I've bisected it to #3244, and the problematic part seems to be going from rust 1.68 to 1.69. On 9c43680 (main right now), I don't have the issue if I force compiling with 1.68

  3. imotov commented on May 16, 2023

    @imotov
    CollaboratorAuthor

    That's unfortunate. I suspected it might be the case, but was hoping it's just some easy to fix bug in a build script.

  4. imotov commented on May 17, 2023

    @imotov
    CollaboratorAuthor

    @guilload suggested running rustup override set 1.68.0 as a work-around. It worked for me.

  5. imotov commented on May 19, 2023

    @imotov
    CollaboratorAuthor

    I think we might be also affected by bytecodealliance/rustix#562

    I see this all the time while running tests in VSCode on both 1.68 and 1.69

     *  Executing task: cargo test --package quickwit-indexing --lib --all-features -- actors::indexing_service::tests --nocapture 
    
    warning: /home/igor/Projects/quickwit-oss/quickwit/quickwit/Cargo.toml: unused manifest key: workspace.rust-version
        Blocking waiting for file lock on build directory
       Compiling rustix v0.36.13
       Compiling procfs v0.14.2
       Compiling prometheus v0.13.3
       Compiling quickwit-common v0.6.0 (/home/igor/Projects/quickwit-oss/quickwit/quickwit/quickwit-common)
    
  6. sunfishcode commented on May 19, 2023

    @sunfishcode

    Could you try adding --verbose? With this flag, cargo adds "Dirty" messages which indicate what prompted it to perform rebuilds.

  7. imotov commented on May 19, 2023

    @imotov
    CollaboratorAuthor

    @sunfishcode with --verbose I get this:

           Dirty rustix v0.36.13: the dependency build_script_build was rebuilt (1684521189.122302115s, 13h 21m 42s after last build at 1684473087.941573652s)
       Compiling rustix v0.36.13
    .. skipped ..
         Running `rustc --crate-name rustix --edition=2018 /home/igor/.cargo/registry/src/github.com-1ecc6299db9ec823/rustix-0.36.13/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=110 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=0 --cfg 'feature="default"' --cfg 'feature="fs"' --cfg 'feature="io-lifetimes"' --cfg 'feature="libc"' --cfg 'feature="param"' --cfg 'feature="process"' --cfg 'feature="std"' --cfg 'feature="thread"' --cfg 'feature="use-libc-auxv"' -C metadata=b0502dcc57ded481 -C extra-filename=-b0502dcc57ded481 --out-dir /home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps -L dependency=/home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps --extern bitflags=/home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps/libbitflags-bb8c1d003de5b446.rmeta --extern io_lifetimes=/home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps/libio_lifetimes-41a94e0c35a418b1.rmeta --extern libc=/home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps/liblibc-f7fb825032d01339.rmeta --extern linux_raw_sys=/home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps/liblinux_raw_sys-3430e5721cc3c0c7.rmeta --cap-lints allow --cfg linux_raw --cfg asm`
    .. skipped ..
           Dirty procfs v0.14.2: the dependency rustix was rebuilt
       Compiling procfs v0.14.2
    .. skipped ..
           Dirty prometheus v0.13.3: the dependency procfs was rebuilt
       Compiling prometheus v0.13.3
    .. skipped ..
           Dirty quickwit-common v0.6.0 (/home/igor/Projects/quickwit-oss/quickwit/quickwit/quickwit-common): the dependency prometheus was rebuilt
    

    That in turn triggers rebuild of the rest of quickwit codebase that depends on quickwit-common.

  8. imotov commented on May 19, 2023

    @imotov
    CollaboratorAuthor

    @sunfishcode one additional observation that might be important here. We also pull rustix v0.37.19 as part of another dependency and it doesn't have the same issue.

  9. sunfishcode commented on May 19, 2023

    @sunfishcode

    Thanks! Looking into it, this is likely to be due to an issue which was fixed in rustix 0.37, so I've now backported the fix to 0.36 and released it in 0.36.14.

  10. imotov commented on May 20, 2023

    @imotov
    CollaboratorAuthor

    @sunfishcode wow, that was fast! Thanks a lot, that really helps. While it doesn't solve the original issue (it seems that we have a somewhat similar problem with proc-macro2) the new version resolved many issues that I had in VS Code interactions while switching between building and running tests.

  11. imotov commented on May 20, 2023

    @imotov
    CollaboratorAuthor

    I think I figured it out. It looks like a regression in rust. Unfortunately, I cannot reproduce it using a small project with a manageable size, but I know the mechanism that is causing the issue and know how to fix it.

    I suspect the issue is triggered by this change in 1.69.0 that is producing different command lines for building crates with edition = "2018" depending on how you build it. We have quite a few of these in our dependency tree, but it all starts with unicode_ident. When it is built using cargo build command it is compiled like this

    Running `CARGO=/home/igor/.rustup/toolchains/1.69-aarch64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=unicode_ident CARGO_MANIFEST_DIR=/home/igor/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-ident-1.0.8 CARGO_PKG_AUTHORS='David Tolnay <[email protected]>' CARGO_PKG_DESCRIPTION='Determine whether characters have the XID_Start or XID_Continue properties according to Unicode Standard Annex #31' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='(MIT OR Apache-2.0) AND Unicode-DFS-2016' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=unicode-ident CARGO_PKG_REPOSITORY='https://github.com/dtolnay/unicode-ident' CARGO_PKG_RUST_VERSION=1.31 CARGO_PKG_VERSION=1.0.8 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=8 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps:/home/igor/.rustup/toolchains/1.69-aarch64-unknown-linux-gnu/lib:/home/igor/.rustup/toolchains/1.69-aarch64-unknown-linux-gnu/lib' rustc --crate-name unicode_ident --edition=2018 /home/igor/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-ident-1.0.8/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=181 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=0 -C metadata=ae9e877358182a13 -C extra-filename=-ae9e877358182a13 --out-dir /home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps -L dependency=/home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps --cap-lints warn`
    

    When it is built using cargo run it is compiled like this:

    Running `CARGO=/home/igor/.rustup/toolchains/1.69-aarch64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=unicode_ident CARGO_MANIFEST_DIR=/home/igor/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-ident-1.0.8 CARGO_PKG_AUTHORS='David Tolnay <[email protected]>' CARGO_PKG_DESCRIPTION='Determine whether characters have the XID_Start or XID_Continue properties according to Unicode Standard Annex #31' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='(MIT OR Apache-2.0) AND Unicode-DFS-2016' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=unicode-ident CARGO_PKG_REPOSITORY='https://github.com/dtolnay/unicode-ident' CARGO_PKG_RUST_VERSION=1.31 CARGO_PKG_VERSION=1.0.8 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=8 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps:/home/igor/.rustup/toolchains/1.69-aarch64-unknown-linux-gnu/lib:/home/igor/.rustup/toolchains/1.69-aarch64-unknown-linux-gnu/lib' rustc --crate-name unicode_ident --edition=2018 /home/igor/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-ident-1.0.8/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=181 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C metadata=6bb1a5f23e3b8481 -C extra-filename=-6bb1a5f23e3b8481 --out-dir /home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps -L dependency=/home/igor/Projects/quickwit-oss/quickwit/quickwit/target/debug/deps --cap-lints warn`
    

    The lines are basically identical with a very small inclusion. The first line has -C debuginfo=0 in it, which also changes fingerprint and causes all that rebuilding. The fix is actually quite silly. Replacing

    [profile.dev]
    debug = 0
    

    with

    [profile.dev]
    debug = false
    

    fixes the issue.

  12. added a commit that references this issue on May 20, 2023
    61109f3
  13. added a commit that references this issue on May 20, 2023
    6bf0b21
  14. imotov commented on May 20, 2023

    @imotov
    CollaboratorAuthor
  15. imotov commented on May 21, 2023

    @imotov
    CollaboratorAuthor

    Based on the description of the issue in the previous comment, we might need to circle back to this. The workaround that I proposed is currently not working in nightly.

  16. added theissue type on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions