@@ -1716,7 +1716,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
17161716
17171717 let codegen_units = codegen_units. unwrap_or_else ( || {
17181718 match opt_level {
1719- // If we're compiling at `-O0` then default to 32 codegen units.
1719+ // If we're compiling at `-O0` then default to 16 codegen units.
17201720 // The number here shouldn't matter too too much as debug mode
17211721 // builds don't rely on performance at all, meaning that lost
17221722 // opportunities for inlining through multiple codegen units is
@@ -1734,7 +1734,21 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
17341734 // unit takes *too* long to build we'll be guaranteed that all
17351735 // cpus will finish pretty closely to one another and we should
17361736 // make relatively optimal use of system resources
1737- OptLevel :: No => 32 ,
1737+ //
1738+ // Another note worth mentioning here, however, is that this number
1739+ // isn't *too* high. When codegen units are increased that means we
1740+ // currently have to codegen `#[inline]` functions into each codegen
1741+ // unit, which means the more codegen units we're using the more we
1742+ // may be generating. In other words, increasing codegen units may
1743+ // increase the overall work the compiler does. If we don't have
1744+ // enough cores to make up for this loss then increasing the number
1745+ // of codegen units could become an overall loss!
1746+ //
1747+ // As a result we choose a hopefully conservative value 16, which
1748+ // should be more than the number of cpus of most hardware compiling
1749+ // Rust but also not too much for 2-4 core machines to have too much
1750+ // loss of compile time.
1751+ OptLevel :: No => 16 ,
17381752
17391753 // All other optimization levels default use one codegen unit,
17401754 // the historical default in Rust for a Long Time.
0 commit comments