Skip to content

Commit fe78af4

Browse files
committed
rustc: Don't read both rlib and dylib metadata
This is an optimization which is quite impactful for compiling small crates. Reading libstd's metadata takes about 50ms, and a hello world before this change took about 100ms (this change halves that time). Recent changes made it such that this optimization wasn't performed, but I think it's a better idea do to this for now. See rust-lang#10786 for tracking this issue.
1 parent e2d34d7 commit fe78af4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Diff for: src/librustc/metadata/loader.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,23 @@ impl<'a> Context<'a> {
317317
// read the metadata from it if `*slot` is `None`. If the metadata couldn't
318318
// be read, it is assumed that the file isn't a valid rust library (no
319319
// errors are emitted).
320-
//
321-
// FIXME(#10786): for an optimization, we only read one of the library's
322-
// metadata sections. In theory we should read both, but
323-
// reading dylib metadata is quite slow.
324320
fn extract_one(&mut self, m: HashSet<Path>, flavor: &str,
325321
slot: &mut Option<MetadataBlob>) -> Option<Path> {
326322
let mut ret = None::<Path>;
327323
let mut error = 0;
328324

325+
if slot.is_some() {
326+
// FIXME(#10786): for an optimization, we only read one of the
327+
// library's metadata sections. In theory we should
328+
// read both, but reading dylib metadata is quite
329+
// slow.
330+
if m.len() == 0 {
331+
return None
332+
} else if m.len() == 1 {
333+
return Some(m.move_iter().next().unwrap())
334+
}
335+
}
336+
329337
for lib in m.move_iter() {
330338
info!("{} reading metadata from: {}", flavor, lib.display());
331339
let metadata = match get_metadata_section(self.os, &lib) {

0 commit comments

Comments
 (0)