Skip to content

Commit

Permalink
Auto merge of rust-lang#118496 - SparrowLii:parallel_3, r=<try>
Browse files Browse the repository at this point in the history
perf test for removing some parallelism in `encode_metadata`

perf test for rust-lang#118488
  • Loading branch information
bors committed Dec 1, 2023
2 parents a1c65db + 1880cdb commit 3227369
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
22 changes: 7 additions & 15 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,21 +2193,13 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path) {
// there's no need to do dep-graph tracking for any of it.
tcx.dep_graph.assert_ignored();

join(
|| encode_metadata_impl(tcx, path),
|| {
if tcx.sess.threads() == 1 {
return;
}
// Prefetch some queries used by metadata encoding.
// This is not necessary for correctness, but is only done for performance reasons.
// It can be removed if it turns out to cause trouble or be detrimental to performance.
join(|| prefetch_mir(tcx), || tcx.exported_symbols(LOCAL_CRATE));
},
);
}

fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
if tcx.sess.threads() != 1 {
// Prefetch some queries used by metadata encoding.
// This is not necessary for correctness, but is only done for performance reasons.
// It can be removed if it turns out to cause trouble or be detrimental to performance.
join(|| prefetch_mir(tcx), || tcx.exported_symbols(LOCAL_CRATE));
}

let mut encoder = opaque::FileEncoder::new(path)
.unwrap_or_else(|err| tcx.sess.emit_fatal(FailCreateFileEncoder { err }));
encoder.emit_raw_bytes(METADATA_HEADER);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ written to standard error output)"),
/// in the future. Note that -Zthreads=0 is the way to get
/// the num_cpus behavior.
#[rustc_lint_opt_deny_field_access("use `Session::threads` instead of this field")]
threads: usize = (1, parse_threads, [UNTRACKED],
threads: usize = (8, parse_threads, [UNTRACKED],
"use a thread pool with N threads"),
time_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
"measure time of each LLVM pass (default: no)"),
Expand Down

0 comments on commit 3227369

Please sign in to comment.