I have a Rust workspace at GitHub - deltachat/deltachat-core-rust: Delta Chat Rust Core library, used by Android/iOS/desktop apps, bindings and bots
Checked out tag v1.121.0, commit a8551510cdb5be7a35ebd3574df79d15a4fa471a
I am building the same workspace with various commands and observe the size of the target/
folder and the number of fingerprints for the aho-corasick
dependency which is a transitive dependency of the regex
crate.
I am using Rust 1.72 installed from the Arch Linux package rust
without rustup. RUSTFLAGS
variable is set to use mold
: RUSTFLAGS=-C linker=clang -C link-arg=-fuse-ld=/usr/bin/mold
.
- Remove
target/
dir withrm -fr target
. - Run
cargo test
. The test finishes, at this pointtarget/
dir is 2.7G in size. There is a single build ofaho-corasick
:
$ for f in target/debug/.fingerprint/aho-corasick-*/lib-aho_corasick.json; do cat $f; echo; done
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":2477126214476020920,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,11093490409464552011]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-37295c684f6d8731/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
- Run
cargo build
.target/
dir is now 3.6G. There are two fingerprints foraho-corasick
:
$ for f in target/debug/.fingerprint/aho-corasick-*/lib-aho_corasick.json; do cat $f; echo; done
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":2477126214476020920,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,11093490409464552011]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-37295c684f6d8731/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":1802155187536016546,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,12497508451996929950]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-59155b355c38f51a/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
- Run
cargo check
.target/
dir is now 3.9G.aho-corasick
has 3 fingerprints:
$ for f in target/debug/.fingerprint/aho-corasick-*/lib-aho_corasick.json; do cat $f; echo; done
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":2477126214476020920,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,11093490409464552011]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-37295c684f6d8731/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":1802155187536016546,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,12497508451996929950]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-59155b355c38f51a/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":10570948055378307092,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,6704056115335731527]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-d4fc41e9be6f1168/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
- Run
cargo clippy
.target/
dir is now 4.0G. There are still 3 fingerprints foraho-corasick
:
$ for f in target/debug/.fingerprint/aho-corasick-*/lib-aho_corasick.json; do cat $f; echo; done
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":2477126214476020920,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,11093490409464552011]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-37295c684f6d8731/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":1802155187536016546,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,12497508451996929950]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-59155b355c38f51a/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":10570948055378307092,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,6704056115335731527]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-d4fc41e9be6f1168/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
- Run
cargo check --workspace
.target/
dir is now 4.5G. There are still 3 fingerprints foraho-corasick
:
$ for f in target/debug/.fingerprint/aho-corasick-*/lib-aho_corasick.json; do cat $f; echo; done
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":2477126214476020920,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,11093490409464552011]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-37295c684f6d8731/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":1802155187536016546,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,12497508451996929950]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-59155b355c38f51a/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":10570948055378307092,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,6704056115335731527]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-d4fc41e9be6f1168/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
- Run
cargo check --workspace --all-targets
. This processes benchmarks as well that were ignored up to this point.target/
dir is now 5.1G. There are now 4 fingerprints foraho-corasick
:
$ for f in target/debug/.fingerprint/aho-corasick-*/lib-aho_corasick.json; do cat $f; echo; done
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":7825666741280757929,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,11611369910886740696]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-029edd760a784a0c/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":2477126214476020920,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,11093490409464552011]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-37295c684f6d8731/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":1802155187536016546,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,12497508451996929950]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-59155b355c38f51a/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
{"rustc":17224161603147387896,"features":"[\"default\", \"perf-literal\", \"std\"]","target":12812136000324506373,"profile":10570948055378307092,"path":6634768422494688907,"deps":[[6893260508610722743,"memchr",false,6704056115335731527]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/aho-corasick-d4fc41e9be6f1168/dep-lib-aho_corasick"}}],"rustflags":["-C","linker=clang","-C","link-arg=-fuse-ld=/usr/bin/mold"],"metadata":13904389431191498124,"config":2202906307356721367,"compile_kind":0}
Note that I have not even made any --release
builds, all the builds above have the same "profile root" (debug). Yet there are four fingerprints for the same dependency with the same features enabled. The difference is in the "profile" field and "deps" field.
Why the "profile" is different? Is it a hash of the profile structure? How to check which fields differ?
What is the last number in the "deps" array item? Why does it differ? I guess it is the firgerprint of dependency itself from the DepFingerprint
structure.
I want to avoid building the same dependency four times in the debug build consuming disk space and compilation time. It seems completely unnecessary to rebuild it more than one time even when switching between the debug build and release build, after all this is not done for libc and standard library, so why should it be done for basic dependencies? Workspace even has optimizations for all dependencies outside workspace enabled as suggested in the Cargo Book:
[profile.dev.package."*"]
opt-level = "z"