@nikomatsakis
Yeah I think that’s basically what I’m proposing, and I also think it’s what happens today as well. Monomorphizations are a bit of a wrench as I assume they just get thrown in whatever the current codegen unit is (as opposed to in a more principled manner). The only point at which we rotate codegen units, however, is right here when we walk into a new module.
I feel that a module-level codegen unit is a nice balance between predictability and size. Most modules correspond to one file, and most files are of a reasonable size. It’s at least fair I think to say “if you want your compiles to be faster, write smaller modules”. All that, plus most projects benefitting the most from better compile times probably have > 8 modules to get benefits on everyone’s computers.
@cristicbz
I do think it’s a good point that smaller projects tend to configure less than larger ones, but I don’t think that “big projects” are the only ones to benefit here. I suspect that there’s quite a few projects in the category of “debug runtime is too slow for iteration”, like games, which will want faster optimized compiles and this is a great means to get there.
As a data point, I wouldn’t consider Cargo/rustfmt to be large projects, but they have significant speedups in compile time with multiple codegen units. Cargo drops from 3 minutes to 2, and rusftmt drops from 3:15 to 1:33.
I agree that we don’t want to have multiple flags, but I also have proposed 0 new flags here. There have been some thoughts about a “debug opt” mode but my claim is that we can avoid that by just saying that you have N codegen units by default. Having only one codegen unit should be considered just another extra optimization for those who want to try it, but the evidence shows to me that the compile time wins outweigh the minor loss in perf here and there. (e.g. this is the the same reason we disable LTO by default, it’s just far too slow to get any real benefit)