Why is fat LTO so slow?

75 points tontsa_

Recently, I noticed that the Rust compiler is quite slow. Or to be precise, it's not the compilation that bothers me. It's the linking process. Or at least so I thought.

As it turns out, the linker was not the problem. I switched to mold and expected to see great compilation time improvements. To my disappointment, the release build didn't get any faster and the debug build did so only by a few seconds (don't get me wrong, this is still better than nothing). The real problem seems to be LTO. I was using fat LTO the whole time and when trying out thin LTO, the compilation time dropped from 2 minutes to about 1 minute 15 seconds, which is a huge improvement. I also noticed the binary size going from about 8,2 megabytes to 9,7 megabytes. In terms of performance, I could barely notice a difference. Now, I have two questions:

  1. Why is fat LTO single threaded?
  2. Is it even more performant than thin LTO, and if not, what causes the increased binary size in thin LTO (or in other words, is fat LTO even worth it)?