You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Disappointingly small speed-ups on Rust files #257
I'm building Firefox on Linux, on my fast i9 machine with 14 physical cores and 28 virtual cores. Here is my mozconfig:
ac_add_options --enable-optimize
ac_add_options --enable-debug
ac_add_options --enable-linker=lld
ac_add_options --disable-elf-hack # needed because of bug 1423822
ac_add_options --with-ccache=sccache
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/o64xlldscc
I do a full build (mach build), then do touch servo/components/style/stylist.rs followed by mach build binaries. This rebuilds four rust crates (style, geckoservo, gkrust-shared, gkrust) and then links libxul.so.
sccache kicks in for the rebuild -- sccache -s confirms it:
Compile requests 5
Compile requests executed 4
Cache hits 5
Cache misses 0
Cache timeouts 0
Cache read errors 0
Forced recaches 0
Cache write errors 0
Compilation failures 0
Cache errors 0
Non-cacheable compilations 0
Non-cacheable calls 0
Non-compilation calls 1
Unsupported compiler calls 0
Average cache write 0.000 s
Average cache read miss 0.000 s
Average cache read hit 0.000 s
Cache location Local disk: "/home/njn/.cache/sccache"
Cache size 10 GiB
Max cache size 10 GiB
Here is the time for the sccache rebuild:
real 0m25.376s
user 0m17.324s
sys 0m8.773s
Compare it to the equivalent rebuild when mozconfig doesn't enable sccache:
real 0m28.248s
user 0m36.627s
sys 0m12.212s
With sccache enabled, less work is being done, but the wall time is only 3 seconds better. This is a small enough improvement that I initially thought sccache wasn't working.
After doing some more testing, I've come to conclusion that sccache should not be used for Rust files in Firefox for configurations where incremental compilation is enabled (i.e. non-release builds).
Here are some timings for a nocache config, a --with-ccache=sccache config (which caches C++ and Rust), and a --enable-ccache (which only caches C++).
Build from scratch:
nocache 9m6s
sccache 11m6s
ccache 9m52s
Add comment at start of servo/components/style/stylist.rs + mach build binaries:
nocache 0m37s
sccache 1m53s
ccache 0m37s
Add comment at end of servo/components/style/stylist.rs + mach build binaries:
nocache 0m27s
sccache 1m22s
ccache 0m28s
sccache only wins in the unrealistic "touch" case, and in that case only by a small amount. But the costs in the other cases are large, especially the last two "minor change" cases.
I personally only use 3, because ccache isn't claimed to work with MSVC as far as I know. And with 3, there is no way to disable sccache for Rust currently.
sccache only wins in the unrealistic "touch" case, and in that case only by a small amount. But the costs in the other cases are large, especially the last two "minor change" cases.
I'd like to state that I take issue with your methodology, first (but that's OK, let's find the right practical solution). sccache doesn't have much benefit for incremental rebuilds, even if it's recompiling the same source--the bigger wins are for clobber builds where the same sources are built again, where we can pull them fully from cache.
That being said, incremental compilation does change the calculus. In #236@alexcrichton suggested that sccache should refuse to cache compilations where incremental compilation is enabled, which might be sufficient to avoid this--sccache could parse the commandline and refuse to cache, which would result in it simply running rustc every time with a much smaller overhead. If someone wanted to try that out, you'd just need to check for -C incremental=...in the Rust commandline parsing code right here.
I don't think we should disable sccache entirely for Rust compilation in developer configurations, because cargo only enables incremental compilation for crates in path dependencies (i.e., not from crates.io), which makes sense, as developers are not editing the sources of their crates.io dependencies and doing incremental builds.
Longer-term we have discussed making sccache able to cache the incremental compilation outputs so that it could do better in this scenario, but I need to have a discussion with @alexcrichton and @michaelwoerister to figure out the details of that and neither of them was at the SF All Hands so it hasn't happened yet. :)
OK, I wrote the patch I suggested. I did some tests using a simple test crate. I compared the build time of a fresh build (cargo clean; cargo build), then a build after touch src/lib.rs across rustc without sccache, rustc with sccache from current master, and sccache with the patch I wrote. @nnethercote if you could repeat your tests building Firefox with this version of sccache I would be interested to see the results. I think this should mitigate the overhead and let Rust's incremental compilation do its thing without harming the usefulness of sccache for crates compiled non-incrementally.
I tried the patch. I can't work out if I did something wrong, but I can't detect any difference between my installed sccache and my locally built one with the patch applied. For my "add a (unique) comment to the start of stylist.rs and recompile" use case:
no sccache: 43s
system sccache: 2m0s
patched sccache: 2m0s
I added some logging to sccache to work out what was going on. The eprintln! I added to main() in src/main.rs was hit, but the one I added to the top-level parse_arguments() in src/compiler/rust.rs was not hit... which would explain the lack of effect -- the changed code isn't being executed, AFAICT.
Here's my mozconfig for use with the patched sccache, in case that's useful:
Oh, since sccache spawns a background daemon, you'll want to run sccache --stop-server between tests if you're going to test different sccache versions.
touch servo/components/style/stylist.rs + mach build binaries:
- no sccache
real 0m34.555s
user 0m46.579s
sys 0m13.147s
- sccache
real 0m30.369s
user 0m28.090s
sys 0m8.908s
- patched sccache
real 0m33.426s
user 0m46.755s
sys 0m12.637s
Add comment at start of servo/components/style/stylist.rs + mach build binaries:
- no sccache
real 0m42.899s
user 1m17.157s
sys 0m13.679s
- sccache
real 1m59.212s
user 0m28.538s
sys 0m9.292s
- patched sccache
real 0m42.774s
user 1m16.826s
sys 0m13.609s
In short: it works! The patched sccache case has the same (good) behaviour as the no sccache case.
@luser : I think this patch is good to land. And I think it's worth doing a new release for it, so Firefox devs can take advantage.
Activity
nnethercote commentedon Jun 27, 2018
After doing some more testing, I've come to conclusion that sccache should not be used for Rust files in Firefox for configurations where incremental compilation is enabled (i.e. non-release builds).
Here are some timings for a nocache config, a --with-ccache=sccache config (which caches C++ and Rust), and a --enable-ccache (which only caches C++).
Build from scratch:
nocache 9m6s
sccache 11m6s
ccache 9m52s
touch servo/components/style/stylist.rs + mach build binaries:
nocache 0m28s
sccache 0m25s
ccache 0m29s
Add comment at start of servo/components/style/stylist.rs + mach build binaries:
nocache 0m37s
sccache 1m53s
ccache 0m37s
Add comment at end of servo/components/style/stylist.rs + mach build binaries:
nocache 0m27s
sccache 1m22s
ccache 0m28s
sccache only wins in the unrealistic "touch" case, and in that case only by a small amount. But the costs in the other cases are large, especially the last two "minor change" cases.
na-g commentedon Jun 27, 2018
@nnethercote, is
mk_add_options "export RUSTC_WRAPPER=sccache"no longer needed?nnethercote commentedon Jun 27, 2018
My understanding is that:
export RUSTC_WRAPPER=sccachesetssccacheas the wrapper for Rust compilation.ac_add_options --enable-ccachesetsccacheas the wrapper for C/C++ compilation.ac_add_options --with-ccache=sccachesetssccacheas the wrapper for Rust and C/C++ compilation.So it makes sense to combine 1 with 2, but it doesn't make sense to combine 1 with 3 or 2 with 3.
upsuper commentedon Jun 28, 2018
I personally only use 3, because ccache isn't claimed to work with MSVC as far as I know. And with 3, there is no way to disable sccache for Rust currently.
luser commentedon Jul 2, 2018
I'd like to state that I take issue with your methodology, first (but that's OK, let's find the right practical solution). sccache doesn't have much benefit for incremental rebuilds, even if it's recompiling the same source--the bigger wins are for clobber builds where the same sources are built again, where we can pull them fully from cache.
That being said, incremental compilation does change the calculus. In #236 @alexcrichton suggested that sccache should refuse to cache compilations where incremental compilation is enabled, which might be sufficient to avoid this--sccache could parse the commandline and refuse to cache, which would result in it simply running rustc every time with a much smaller overhead. If someone wanted to try that out, you'd just need to check for
-C incremental=...in the Rust commandline parsing code right here.I don't think we should disable sccache entirely for Rust compilation in developer configurations, because cargo only enables incremental compilation for crates in path dependencies (i.e., not from crates.io), which makes sense, as developers are not editing the sources of their crates.io dependencies and doing incremental builds.
Longer-term we have discussed making sccache able to cache the incremental compilation outputs so that it could do better in this scenario, but I need to have a discussion with @alexcrichton and @michaelwoerister to figure out the details of that and neither of them was at the SF All Hands so it hasn't happened yet. :)
Don't cache Rust compiles with incremental compilation. Fixes mozilla…
luser commentedon Jul 3, 2018
OK, I wrote the patch I suggested. I did some tests using a simple test crate. I compared the build time of a fresh build (
cargo clean; cargo build), then a build aftertouch src/lib.rsacross rustc without sccache, rustc with sccache from current master, and sccache with the patch I wrote. @nnethercote if you could repeat your tests building Firefox with this version of sccache I would be interested to see the results. I think this should mitigate the overhead and let Rust's incremental compilation do its thing without harming the usefulness of sccache for crates compiled non-incrementally.nnethercote commentedon Jul 5, 2018
I tried the patch. I can't work out if I did something wrong, but I can't detect any difference between my installed sccache and my locally built one with the patch applied. For my "add a (unique) comment to the start of stylist.rs and recompile" use case:
I added some logging to sccache to work out what was going on. The
eprintln!I added tomain()insrc/main.rswas hit, but the one I added to the top-levelparse_arguments()insrc/compiler/rust.rswas not hit... which would explain the lack of effect -- the changed code isn't being executed, AFAICT.Here's my mozconfig for use with the patched sccache, in case that's useful:
luser commentedon Jul 5, 2018
Oh, since sccache spawns a background daemon, you'll want to run
sccache --stop-serverbetween tests if you're going to test different sccache versions.nnethercote commentedon Jul 5, 2018
That would explain it! Thanks for the tip. I won't be able to test this again until early next week, I'll report back then.
nnethercote commentedon Jul 11, 2018
Ok, results with
sccache --stop-server:In short: it works! The patched sccache case has the same (good) behaviour as the no sccache case.
@luser : I think this patch is good to land. And I think it's worth doing a new release for it, so Firefox devs can take advantage.
luser commentedon Jul 11, 2018
Thanks for testing! I will merge that and release a new version.
Don't cache Rust compiles with incremental compilation. Fixes mozilla…
Don't cache Rust compiles with incremental compilation. Fixes mozilla…