about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-04-07 13:13:21 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-04-08 00:03:11 -0700
commitcced02fcacfe4a6d1598e987003e00aa65713efb (patch)
treec9f5314c1c12b8ea57a69169cd375e94120fb59d /src
parent5367c32c7ddb873babec89f739a936409d45476a (diff)
downloadrust-cced02fcacfe4a6d1598e987003e00aa65713efb.tar.gz
rust-cced02fcacfe4a6d1598e987003e00aa65713efb.zip
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 #10786 for tracking this issue.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/metadata/loader.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs
index 8dea36d8152..5a342e39d70 100644
--- a/src/librustc/metadata/loader.rs
+++ b/src/librustc/metadata/loader.rs
@@ -317,15 +317,23 @@ impl<'a> Context<'a> {
     // read the metadata from it if `*slot` is `None`. If the metadata couldn't
     // be read, it is assumed that the file isn't a valid rust library (no
     // errors are emitted).
-    //
-    // FIXME(#10786): for an optimization, we only read one of the library's
-    //                metadata sections. In theory we should read both, but
-    //                reading dylib metadata is quite slow.
     fn extract_one(&mut self, m: HashSet<Path>, flavor: &str,
                    slot: &mut Option<MetadataBlob>) -> Option<Path> {
         let mut ret = None::<Path>;
         let mut error = 0;
 
+        if slot.is_some() {
+            // FIXME(#10786): for an optimization, we only read one of the
+            //                library's metadata sections. In theory we should
+            //                read both, but reading dylib metadata is quite
+            //                slow.
+            if m.len() == 0 {
+                return None
+            } else if m.len() == 1 {
+                return Some(m.move_iter().next().unwrap())
+            }
+        }
+
         for lib in m.move_iter() {
             info!("{} reading metadata from: {}", flavor, lib.display());
             let metadata = match get_metadata_section(self.os, &lib) {