Repository navigation
Significantly slower --emit=metadata #47267
Description
I have found a significant time increase when I use "rustc --emit=metadata". I have located the source of such difference between two Nightlies, that I've named A and B, the time is for my code:
A:
rustup default nightly-2017-12-14
rustc 1.24.0-nightly (f8af59d95 2017-12-13)
commit-hash: f8af59d95225d122e38bb5dceb1027844d4ce170
host: x86_64-pc-windows-gnu
--emit=metadata time: 4.35 seconds
B:
rustup default nightly-2017-12-15
rustc 1.24.0-nightly (0077d128d 2017-12-14)
commit-hash: 0077d128d33543290140763ce7d84d05eb57c40a
host: x86_64-pc-windows-gnu
--emit=metadata time: 5.22 seconds
If you perform a complete compilation instead of just --emit=metadata the timing difference between the A and B compiler is of course much smaller. But --emit=metadata time is important to verify the code.
To show an example I've done:
cargo check --all
On rust-ndarray version 0.11.0, with both A and B. Then I've cleaned the directory:
rust-ndarray-master\target\debug\deps
And I've done "cargo check --all" again for both both A and B. This is not the best test for this problem, but it shows a difference (25.76 seconds for A, and 26.75 seconds for B), the difference percentage is small because it's not equivalent to just a "--emit=metadata".
Activity
eddyb commentedon Jan 8, 2018
cc @michaelwoerister
michaelwoerister commentedon Jan 8, 2018
IIRC, metadata generation is the first point where we compute the MIR of most functions, so the slowdown does not have to be specific to metadata encoding.
alexcrichton commentedon Jan 8, 2018
According to the list of changes the candidates probably are:
@leonardo-m would you be able to share detailed instructions of how to reproduce? Testing the two nightlies in question on rust-ndarray/ndarray@bda4c0d doesn't show much differnce to me for
cargo check --alland incremental changesleonardo-m commentedon Jan 9, 2018
So far I haven't found a better way to reproduce the problem, my code is not public. But if no one else is having this problem, then it's just a problem of my code, and I'll close down this issue.
A simple thing that I didn't think about using is "-Ztime-passes --emit=metadata":
The only significant difference I am seeing in those two listings is for the borrow checking:
A: time: 1.079; rss: 186MB borrow checking
B: time: 1.955; rss: 188MB borrow checking
So the cause could be the NLL changes. I have an open issue about NLL ( #47022 ), so I can't compile my code with
#![feature(nll)]. But I've seen that nll multiplies by 5.5X my "--emit=metadata" compilation time.eddyb commentedon Jan 9, 2018
cc @nikomatsakis
nikomatsakis commentedon Jan 11, 2018
Huh, that's interesting. I don't have much of an idea why that would be. It'd be really nice if we could try to reproduce this with some standalone file.
nikomatsakis commentedon Jan 11, 2018
I'm tagging it as WG-compiler-nll for now.
leonardo-m commentedon Jan 15, 2018
This is a problem related but different from the main one discussed above. The last Nigtly (1.25.0 3f92e8d 2018-01-14) is finally able to compile my code if I add the nll feature. But compiling it with "--emit=metadata" goes from 5.30 seconds to 31.84 seconds (about 6X slower). If I also use "-Ztime-passes" I see the differences:
michaelwoerister commentedon Jan 16, 2018
Ouch
:)nikomatsakis commentedon Jan 16, 2018
@leonardo-m perhaps you can run with
perfand give some kind of profiling? It's kind of hard to diagnose what the problem is without some better way to reproduce.(How private is the code? If you are willing to send via e-mail, I'd of course promise not to redistribute.)
leonardo-m commentedon Jan 18, 2018
Yes, I could send you all the code. But first let's try with an example I've found. This small program shows some timings difference compiling with "--emit=metadata" (0.47 seconds with nll, and 0.27 seconds without):
nikomatsakis commentedon Jan 18, 2018
@leonardo-m thanks =)
nikomatsakis commentedon Jan 24, 2018
Some notes on the runtime of this test that I've extracted from profiling:
librustc_mir::borrow_checknikomatsakis commentedon Jan 24, 2018
Browsing the MIR for the main function is interesting (here is a gist), you can definitely see some of the density/sparsity of the region values.
spastorino commentedon Jan 26, 2018
Some numbers of @leonardo-m example, with and without this PR #47766
I'm showing the average numbers after running
time rustcseveral times.Without PR
With PR
With PR, NLL turned off
So, there's still a lot to improve but getting closer 😄
leonardo-m commentedon Feb 5, 2018
The compile time with --emit=metadata and nll feature has improved a bit, but it's still about 5X slower. The compile time without the nll has improved in the last two nightlies and it's now almost OK.
leonardo-m commentedon May 20, 2018
Since the last Nightly the compiler improvements have essentially put the compiler back to the original performance discussed here. The performance of the NLL feature is discussed elsewhere, so I close down this issue.