Closed
Description
A local build of Servo's style
crate shows a huge amount of time (46 seconds!) in name resolution. It turns out that basically all of it is calling span_to_snippet
, specifically this one. That's a lot of unused imports!
Sure enough if we create a synthetic file locally with this script:
N=20000
echo '#![allow(unused)]' > lots-of-unused.rs
for i in `seq 1 $N`; do
echo "use foo as foo$i;" >> lots-of-unused.rs
done
echo 'fn foo() {}' >> lots-of-unused.rs
echo 'fn main() {}' >> lots-of-unused.rs
echo > lots-of-used.rs
for i in `seq 1 $N`; do
echo "use test::foo$i;" >> lots-of-used.rs
done
echo 'mod test {' >> lots-of-used.rs
for i in `seq 1 $N`; do
echo "pub fn foo$i() {}" >> lots-of-used.rs
done
echo '}' >> lots-of-used.rs
echo 'fn main() {' >> lots-of-used.rs
for i in `seq 1 $N`; do
echo "foo$i();" >> lots-of-used.rs
done
echo '}' >> lots-of-used.rs
we find:
$ rustc +nightly -V
rustc 1.21.0-nightly (aac223f4f 2017-07-30)
$ sh foo.sh
$ rustc +nightly lots-of-used.rs -Z time-passes 2>&1 | grep 'name resolution'
time: 0.033; rss: 164MB name resolution
$ rustc +nightly lots-of-unused.rs -Z time-passes 2>&1 | grep 'name resolution'
time: 1.139; rss: 136MB name resolution
That's a lot of time spent processing unused imports!
The slowdown here isn't quite the same as the style crate, unfortunately. The style crate only has ~7k unused imports, which apparently takes it 48s in that profile. In any case the intent here is clear, lots of unused imports seem to slow down compilation, and the style
crate looks to have a lot of unused imports!