Skip to content

Use item count to estimate CGU size. #113649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ impl<'tcx> MonoItem<'tcx> {
}
}

pub fn size_estimate(&self, tcx: TyCtxt<'tcx>) -> usize {
pub fn size_estimate(&self, _tcx: TyCtxt<'tcx>) -> usize {
match *self {
MonoItem::Fn(instance) => {
MonoItem::Fn(_instance) => {
// Estimate the size of a function based on how many statements
// it contains.
tcx.instance_def_size_estimate(instance.def)
//tcx.instance_def_size_estimate(instance.def)
1
}
// Conservatively estimate the size of a static declaration
// or assembly to be 1.
Expand Down Expand Up @@ -321,8 +322,7 @@ impl<'tcx> CodegenUnit<'tcx> {
}

pub fn compute_size_estimate(&mut self, tcx: TyCtxt<'tcx>) {
// Estimate the size of a codegen unit as (approximately) the number of MIR
// statements it corresponds to.
// Estimate the size of a codegen unit as the number of items in it.
self.size_estimate = self.items.keys().map(|mi| mi.size_estimate(tcx)).sum();
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ fn merge_codegen_units<'tcx>(
// Having multiple CGUs can drastically speed up compilation. But for
// non-incremental builds, tiny CGUs slow down compilation *and* result in
// worse generated code. So we don't allow CGUs smaller than this (unless
// there is just one CGU, of course). Note that CGU sizes of 100,000+ are
// there is just one CGU, of course). Note that CGU sizes of 3,000+ are
// common in larger programs, so this isn't all that large.
const NON_INCR_MIN_CGU_SIZE: usize = 1800;
const NON_INCR_MIN_CGU_SIZE: usize = 65;

// Repeatedly merge the two smallest codegen units as long as:
// - we have more CGUs than the upper limit, or
Expand Down