Slow compilation time library with reqwest

Hi,
I have a strange problem,
when I link the crate reqwest in a library project the time to compile is unusually high (upto 1 minute), although it is empty. This not happen if I make a binary project

SO: Windows 10
Rust: rustc 1.30.1 (1433507eb 2018-11-07)
Cargo: cargo 1.30.0 (a1a4ad372 2018-11-02)
Toolchain: stable-i686-pc-windows-msvc (default)

First compilation after you add a new dependency is expected to take a long time. Second compilation after a change only in your project should be shorter.

Ok, I didn’t mean the first compilation but the successive ones

That’s a tough one. Try setting RUSTFLAGS to -Zincremental-info or -Ztime-llvm-passes

$ RUSTFLAGS=-Zincremental-info cargo build
   Compiling semver-parser v0.7.0
   Compiling winapi v0.3.6
   Compiling winapi-build v0.1.1
   Compiling version_check v0.1.5
   Compiling rand_core v0.3.0
   Compiling libc v0.2.44
   Compiling siphasher v0.2.3
   Compiling build_const v0.2.1
   Compiling httparse v1.3.3
   Compiling ryu v0.2.7
   Compiling serde v1.0.80
   Compiling native-tls v0.2.2
   Compiling encoding_rs v0.8.12
   Compiling ws2_32-sys v0.2.1
   Compiling kernel32-sys v0.2.2
   Compiling unicase v1.4.2
   Compiling unicase v2.2.0
   Compiling semver v0.9.0
   Compiling rand_core v0.2.2
   Compiling rand_hc v0.1.0
   Compiling rand_isaac v0.1.1
   Compiling rand_xorshift v0.1.0
   Compiling crc v1.8.1
   Compiling rustc_version v0.2.3
   Compiling num_cpus v1.8.0
   Compiling parking_lot_core v0.3.1
   Compiling rand_chacha v0.1.0
   Compiling rand_pcg v0.1.1
   Compiling rand v0.6.1
   Compiling phf_shared v0.7.23
   Compiling mime v0.3.12
   Compiling futures-cpupool v0.1.8
   Compiling net2 v0.2.33
   Compiling rand v0.5.5
   Compiling time v0.1.40
   Compiling schannel v0.1.14
   Compiling phf v0.7.23
   Compiling libflate v0.1.18
   Compiling miow v0.2.1
   Compiling phf_generator v0.7.23
   Compiling uuid v0.7.1
   Compiling serde_urlencoded v0.5.4
   Compiling serde_json v1.0.33
   Compiling phf_codegen v0.7.23
   Compiling mio v0.6.16
   Compiling parking_lot v0.6.4
   Compiling mime_guess v2.0.0-alpha.6
   Compiling tokio-threadpool v0.1.9
   Compiling tokio-reactor v0.1.7
   Compiling tokio-fs v0.1.4
   Compiling tokio-udp v0.1.3
   Compiling tokio-tcp v0.1.2
   Compiling tokio v0.1.13
   Compiling hyper v0.12.16
   Compiling hyper-tls v0.3.1
   Compiling reqwest v0.9.5
   Compiling prova v0.1.0 (C:\CBA\Project\rust\tmp\prova)
[incremental] session directory: 4 files hard-linked
[incremental] session directory: 0 files copied
[incremental]
[incremental] DepGraph Statistics
[incremental] ------------------------------------------------------------------------------------------
[incremental]
[incremental] Total Node Count: 209532
[incremental] Total Edge Count: 609065
[incremental] Total Edge Reads: 706
[incremental] Total Duplicate Edge Reads: 1
[incremental]
[incremental]  Node Kind                           | Node Frequency   | Node Count  | Avg. Edge Count  |
[incremental] -------------------------------------|------------------|-------------|------------------|
[incremental]  InstanceSymbolName                  |            17.9% |       37503 |              8.3 |
[incremental]  GenericsOfItem                      |            13.1% |       27371 |              1.0 |
[incremental]  TypeOfItem                          |            12.4% |       25912 |              1.0 |
[incremental]  ItemAttrs                           |            10.3% |       21535 |              1.0 |
[incremental]  CodegenFnAttrs                      |             7.7% |       16077 |              3.0 |
[incremental]  IsForeignItem                       |             7.7% |       16074 |              1.0 |
[incremental]  SymbolName                          |             7.6% |       15987 |              5.5 |
[incremental]  FnSignature                         |             7.4% |       15580 |              1.5 |
[incremental]  IsConstFn                           |             6.3% |       13124 |              1.0 |
[incremental]  ImplTraitRef                        |             4.8% |       10156 |              1.0 |
[incremental]  AdtDefOfItem                        |             2.6% |        5461 |              3.0 |
[incremental]  UpstreamMonomorphizationsFor        |             1.4% |        2863 |              1.0 |
[incremental]  OriginalCrateName                   |             0.0% |         101 |              1.0 |
[incremental]  CrateHash                           |             0.0% |         101 |              1.0 |
[incremental]  IsPanicRuntime                      |             0.0% |         101 |              1.0 |
[incremental]  CrateDisambiguator                  |             0.0% |         101 |              1.0 |
[incremental]  CrateName                           |             0.0% |         101 |              1.0 |
[incremental]  NativeLibraries                     |             0.0% |         101 |              1.0 |
[incremental]  ExportedSymbols                     |             0.0% |         101 |             35.2 |
[incremental]  IsCompilerBuiltins                  |             0.0% |         101 |              1.0 |
[incremental]  IsNoBuiltins                        |             0.0% |         100 |              1.0 |
[incremental]  MissingLangItems                    |             0.0% |         100 |              1.0 |
[incremental]  GetPanicStrategy                    |             0.0% |         100 |              1.0 |
[incremental]  IsSanitizerRuntime                  |             0.0% |         100 |              1.0 |
[incremental]  DepKind                             |             0.0% |         100 |              1.0 |
[incremental]  UsedCrateSource                     |             0.0% |         100 |              1.0 |
[incremental]  CrateMetadata                       |             0.0% |         100 |              0.0 |
[incremental]  ExtraFileName                       |             0.0% |         100 |              1.0 |
[incremental]  DefinedLangItems                    |             0.0% |         100 |              1.0 |
[incremental]  IsProfilerRuntime                   |             0.0% |         100 |              1.0 |
[incremental]  EraseRegionsTy                      |             0.0% |           5 |              1.0 |
[incremental]  HirBody                             |             0.0% |           4 |              0.0 |
[incremental]  DefSpan                             |             0.0% |           4 |              1.0 |
[incremental]  Hir                                 |             0.0% |           4 |              0.0 |
[incremental]  ExplicitPredicatesOfItem            |             0.0% |           3 |              2.0 |
[incremental]  InferredOutlivesOf                  |             0.0% |           3 |              1.0 |
[incremental]  PredicatesOfItem                    |             0.0% |           3 |              1.0 |
[incremental]  CheckItemWellFormed                 |             0.0% |           3 |              1.0 |
[incremental]  PredicatesDefinedOnItem             |             0.0% |           3 |              2.0 |
[incremental]  ParamEnv                            |             0.0% |           3 |              4.0 |
[incremental]  TraitDefOfItem                      |             0.0% |           3 |              1.0 |
[incremental]  ObjectLifetimeDefaults              |             0.0% |           3 |              1.0 |
[incremental]  HasTypeckTables                     |             0.0% |           3 |              1.0 |
[incremental]  PluginRegistrarFn                   |             0.0% |           2 |              1.0 |
[incremental]  ExternModStmtCnum                   |             0.0% |           2 |              0.0 |
[incremental]  LookupStability                     |             0.0% |           2 |              1.0 |
[incremental]  LookupDeprecationEntry              |             0.0% |           2 |              1.0 |
[incremental]  ForeignModules                      |             0.0% |           1 |              1.0 |
[incremental]  GetLangItems                        |             0.0% |           1 |              1.0 |
[incremental]  HasPanicHandler                     |             0.0% |           1 |              1.0 |
[incremental]  Reachability                        |             0.0% |           1 |              6.0 |
[incremental]  StabilityIndex                      |             0.0% |           1 |              1.0 |
[incremental]  CodegenUnit                         |             0.0% |           1 |              1.0 |
[incremental]  AllLocalTraitImpls                  |             0.0% |           1 |              0.0 |
[incremental]  UpstreamMonomorphizations           |             0.0% |           1 |            101.0 |
[incremental]  MaybeUnusedExternCrates             |             0.0% |           1 |              0.0 |
[incremental]  CoherenceInherentImplOverlapCheck   |             0.0% |           1 |              1.0 |
[incremental]  OutputFilenames                     |             0.0% |           1 |              0.0 |
[incremental]  LinkArgs                            |             0.0% |           1 |              1.0 |
[incremental]  Coherence                           |             0.0% |           1 |              1.0 |
[incremental]  CompileCodegenUnit                  |             0.0% |           1 |              2.0 |
[incremental]  ResolveLifetimes                    |             0.0% |           1 |              1.0 |
[incremental]  GetLibFeatures                      |             0.0% |           1 |              1.0 |
[incremental]  PostorderCnums                      |             0.0% |           1 |              0.0 |
[incremental]  TargetFeaturesWhitelist             |             0.0% |           1 |              0.0 |
[incremental]  Features                            |             0.0% |           1 |              0.0 |
[incremental]  AssociatedItems                     |             0.0% |           1 |              1.0 |
[incremental]  ModuleExports                       |             0.0% |           1 |              0.0 |
[incremental]  ReachableNonGenerics                |             0.0% |           1 |              3.0 |
[incremental]  Krate                               |             0.0% |           1 |              0.0 |
[incremental]  AllCrateNums                        |             0.0% |           1 |              0.0 |
[incremental]  CollectAndPartitionMonoItems        |             0.0% |           1 |              1.0 |
[incremental]  PrivacyAccessLevels                 |             0.0% |           1 |              1.0 |
[incremental]  LintLevels                          |             0.0% |           1 |              1.0 |
[incremental]  HasGlobalAllocator                  |             0.0% |           1 |              1.0 |
[incremental]  TypeckBodiesKrate                   |             0.0% |           1 |              1.0 |
[incremental] ------------------------------------------------------------------------------------------
[incremental]
    Finished dev [unoptimized + debuginfo] target(s) in 1m 39s

The compiler remains a long time on the last phase; seems for the project, not for compiling the crates

Doing
$ CARGO_INCREMENTAL=0 RUSTFLAGS="-Z time-passes -Z time-llvm-passes" cargo build

...
time: 0.005; rss: 150MB     altering libc-99f151b21295eff3.rlib
time: 0.006; rss: 150MB     altering alloc-efb593f382b926d0.rlib
time: 0.006; rss: 150MB     altering core-76bc2fd3c01c937c.rlib
time: 0.008; rss: 150MB     altering compiler_builtins-d7bb3cbd6803fcc3.rlib
time: 61.682; rss: 150MB    running linker
  time: 62.454; rss: 150MB      linking
Finished dev [unoptimized + debuginfo] target(s) in 2m 30s

Is it the linker that takes a long time?

Yup. It looks like MSVC’s linker takes the whole time here. Compile with --verbose to see linker invocation command args.

$ cargo build --verbose
 ...
 Fresh mime_guess v2.0.0-alpha.6
 Fresh hyper v0.12.16
 Fresh hyper-tls v0.3.1
 Fresh reqwest v0.9.5
 Compiling prova v0.1.0 (C:\CBA\Project\rust\tmp\prova)
Running `rustc --crate-name ktree 'src\lib.rs' --color always --crate-type dylib --emit=dep-info,link -C   debuginfo=2 -C metadata=f9247e283efb0425 --out-dir 'C:\CBA\Project\rust\tmp\prova\target\debug\deps' -C 'incremental=C:\CBA\Project\rust\tmp\prova\target\debug\incremental' -L 'dependency=C:\CBA\Project\rust\tmp\prova\target\debug\deps' --extern 'reqwest=C:\CBA\Project\rust\tmp\prova\target\debug\deps\libreqwest-db4c154bb8469a90.rlib'`
Finished dev [unoptimized + debuginfo] target(s) in 1m 01s

It is the last line (Running rustc) that takes more time

I try to compile the library with different toolchain, the result are the following.
With gnu-gcc the time to compile is lower and with msvc x86 or x64 are the same.

I’m n00b so I don’t know if ~15s for compile a nearly empty library (with only reqwest crate) is normal, it could be?

Toolchain: nightly-x686-pc-windows-gnu

$ time cargo build
   Compiling prova v0.1.0 (C:\CBA\Project\rust\tmp\prova)
    Finished dev [unoptimized + debuginfo] target(s) in 15.28s

real    0m15,342s
user    0m0,000s
sys     0m0,015s

Toolchain: nightly-i686-pc-windows-msvc

$ time cargo build
   Compiling prova v0.1.0 (C:\CBA\Project\rust\tmp\prova)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 08s

real    1m8,536s
user    0m0,016s
sys     0m0,000s

Toolchain: nightly-x86_64-pc-windows-msvc

 $ time cargo build
   Compiling prova v0.1.0 (C:\CBA\Project\rust\tmp\prova)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 04s

real    1m4,576s
user    0m0,000s
sys     0m0,000s
1 Like