My Rust build is taking around 20 seconds to build on my new Macbook Pro, sometimes even freezing my computer in the process. I have compared the runtime to an equivalent computer, and there it builds and runs almost instantly.
Using the profiler in Mac Instruments, the execution of my build seems to be doing nothing for most of the 20 seconds, and then only rendering the output at the very end.
I have uninstalled and reinstalled rust and cargo several times with different versions, as well as running cargo clean, with no luck. This occurs for all projects and builds that I have tried.
Any ideas?
I am using macOS Mojave 10.14.6. Have already compared the disk write speeds to another computer and did not see any problems.
@sanxiyn You are likely right, it might be a problem with the linker. When I run rustc with -Z time-passes I get the following output: (after the "linking" line at the end it stalls for ~20 seconds)
The natural next step is to confirm whether two machines have different linkers, and if so, update the slow machine such that it has the same linker as the fast machine.
I admit up front I don't know how to solve this problem and am suggesting in the dark.
So looking at the log time log above, you have ~ 50ish lines, where each line is .00N, .01N, or .02N - adding up to ~ 1 second -- then the linker hangs and makes you wait for ~23 seconds. This further supports @sanxiyn 's intuition that the linker is the problem.
Is it possible to use something like strace or dtrace to trace the system calls? (I'm pretty sure this is possible, I just don't know how to do it on OSX). The goal is to get the terminal to dump all kernel calls. It'll be a bunch of noise at first, but should provide insights during the 20 second wait, to see what precisely it is blocking on.
Disclaimer: I claim no specific knowledge of this problem or how to troubleshoot it.
A quick google of linker problems with MacOS sent me to various mentions of the LLVM LLD linker as a drop-in replacement for the GNU system defaults. It is supposed to be much faster. Is there a way to check if one of your machines has LLD installed and the other does not?
I wouldn't recommend going with lld in macOS. I've tried several times in the past, and it never ends well. I gave it another try using a freshly-build llvm master and it did not work. There are various issues. Sometimes binaries link, sometimes they do not. If they do link, they (for me) always segfault on execution.
If you would like to try it, you can point rustc at your (perhaps freshly built) copy of ld64.lld like so:
Attempting to link C code with clang+lld fails to find libSystem.dylib; the Mach-O support in lld is apparently woefully bitrotted.
Furthermore, allegedly ld64 is not nearly as sluggish as other platform linkers, so the performance boost wouldn't be as great. Which makes me think there may be something else going on with your system that's causing link times to be so high. Disk I/O issues?